All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface com.sun.java.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 MyCellRenederer() {
         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, BasicListCellRenderer

Method Index

 o getListCellRendererComponent(JList, Object, int, boolean, boolean)
Return a component that's been configured to display the specified value.

Methods

 o getListCellRendererComponent
 public abstract 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. Renderer components should report the same preferred size independent of the

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

All Packages  Class Hierarchy  This Package  Previous  Next  Index