KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > motif > MotifComboBoxRenderer


1 /*
2  * @(#)MotifComboBoxRenderer.java 1.13 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 package com.sun.java.swing.plaf.motif;
8
9 /**
10  * A renderer for combo box with motif look and feel
11  *
12  * @version 1.13 12/19/03
13  * @author Arnaud Weber
14  */

15
16 import javax.swing.*;
17 import javax.swing.event.*;
18 import javax.swing.border.*;
19
20 import java.awt.Component JavaDoc;
21 import java.awt.Color JavaDoc;
22
23 import java.io.Serializable JavaDoc;
24
25 /**
26  * Motif rendition of the combo box renderer.
27  * <p>
28  * <strong>Warning:</strong>
29  * Serialized objects of this class will not be compatible with
30  * future Swing releases. The current serialization support is appropriate
31  * for short term storage or RMI between applications running the same
32  * version of Swing. A future release of Swing will provide support for
33  * long term persistence.
34  */

35 public class MotifComboBoxRenderer extends JLabel
36     implements ListCellRenderer, Serializable JavaDoc
37 {
38     protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
39
40     public MotifComboBoxRenderer() {
41     super();
42     setOpaque(true);
43     setBorder(noFocusBorder);
44     }
45
46
47     public Component JavaDoc getListCellRendererComponent(
48         JList list,
49     Object JavaDoc value,
50         int index,
51         boolean isSelected,
52         boolean cellHasFocus)
53     {
54
55         setHorizontalAlignment(SwingConstants.LEFT);
56         if (isSelected) {
57             setBackground(list.getSelectionBackground());
58             setForeground(list.getSelectionForeground());
59         } else {
60             setBackground(list.getBackground());
61             setForeground(list.getForeground());
62         }
63     
64     if (value instanceof Icon) {
65         setIcon((Icon)value);
66     }
67     else {
68         setText((value == null) ? "" : value.toString());
69     }
70     return this;
71     }
72
73
74     /**
75      * A subclass of MotifComboBoxRenderer that implements UIResource.
76      * MotifComboBoxRenderer doesn't implement UIResource
77      * directly so that applications can safely override the
78      * cellRenderer property with MotifListCellRenderer subclasses.
79      * <p>
80      * <strong>Warning:</strong>
81      * Serialized objects of this class will not be compatible with
82      * future Swing releases. The current serialization support is appropriate
83      * for short term storage or RMI between applications running the same
84      * version of Swing. A future release of Swing will provide support for
85      * long term persistence.
86      */

87     public static class UIResource extends MotifComboBoxRenderer
88         implements javax.swing.plaf.UIResource JavaDoc
89     {
90     }
91
92
93
94 }
95
96
97
Popular Tags