KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > ListCellRenderer


1 /*
2  * @(#)ListCellRenderer.java 1.17 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing;
9
10 import java.awt.Component JavaDoc;
11
12
13 /**
14  * Identifies components that can be used as "rubber stamps" to paint
15  * the cells in a JList. For example, to use a JLabel as a
16  * ListCellRenderer, you would write something like this:
17  * <pre>
18  * class MyCellRenderer extends JLabel implements ListCellRenderer {
19  * public MyCellRenderer() {
20  * setOpaque(true);
21  * }
22  * public Component getListCellRendererComponent(
23  * JList list,
24  * Object value,
25  * int index,
26  * boolean isSelected,
27  * boolean cellHasFocus)
28  * {
29  * setText(value.toString());
30  * setBackground(isSelected ? Color.red : Color.white);
31  * setForeground(isSelected ? Color.white : Color.black);
32  * return this;
33  * }
34  * }
35  * </pre>
36  *
37  * @see JList
38  * @see DefaultListCellRenderer
39  *
40  * @version 1.17 12/19/03
41  * @author Hans Muller
42  */

43 public interface ListCellRenderer
44 {
45     /**
46      * Return a component that has been configured to display the specified
47      * value. That component's <code>paint</code> method is then called to
48      * "render" the cell. If it is necessary to compute the dimensions
49      * of a list because the list cells do not have a fixed size, this method
50      * is called to generate a component on which <code>getPreferredSize</code>
51      * can be invoked.
52      *
53      * @param list The JList we're painting.
54      * @param value The value returned by list.getModel().getElementAt(index).
55      * @param index The cells index.
56      * @param isSelected True if the specified cell was selected.
57      * @param cellHasFocus True if the specified cell has the focus.
58      * @return A component whose paint() method will render the specified value.
59      *
60      * @see JList
61      * @see ListSelectionModel
62      * @see ListModel
63      */

64     Component JavaDoc getListCellRendererComponent(
65         JList JavaDoc list,
66         Object JavaDoc value,
67         int index,
68         boolean isSelected,
69         boolean cellHasFocus);
70 }
71
Popular Tags