Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Interface java.awt.swing.ListCellRenderer


public interface ListCellRenderer
Components that are to be used as "rubber stamps" to paint the cells in a JList, must implement this interface. For example to us a JLabel as a ListCellRenderer one would write something like this:
 class MyCellRenderer extends JLabel implements ListCellRenderer {
     public MyCellRenderer() {
         setOpaque(true);
     }
     public Component getListCellRendererComponent(
         JList list, 
         Object value, 
         int index, 
         boolean isSelected, 
         boolean cellHasFocus) 
     {
         setText(value.toString());
         setBackground(isSelected ? Color.red : Color.white);
         setForeground(isSelected ? Color.white : Color.black);
         return this;
     }
 }
 

See Also:
JList, basic.BasicListCellRenderer

Method Summary
Component  getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
Return a component that's been configured to display the specified value.
 

Method Detail

getListCellRendererComponent

public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus)
Return a component that's been configured to display the specified value. The components paint method will be called subsequently to "render" the cell. If it's neccessary to compute the dimensions of the list, e.g. if the list cells aren't fixed size, this method will be called to generate a component to apply getPreferredSize() to.
Parameters:
list - The JList we're painting.
value - The value returned by list.getModel().getElementAt(index).
index - The cells index.
isSelected - True if the specified cell was selected.
cellHasFocus - True if the specified cell has the focus.
Returns:
A component whose paint() method will render the specified value.
See Also:
JList, ListSelectionModel, ListModel

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.