FileDocCategorySizeDatePackage
BasicComboBoxRenderer.javaAPI DocJava SE 6 API4207Tue Jun 10 00:26:46 BST 2008javax.swing.plaf.basic

BasicComboBoxRenderer

public class BasicComboBoxRenderer extends JLabel implements Serializable, ListCellRenderer
ComboBox renderer

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

version
1.22 11/30/05
author
Arnaud Weber

Fields Summary
protected static Border
noFocusBorder
An empty Border. This field might not be used. To change the Border used by this renderer directly set it using the setBorder method.
private static final Border
SAFE_NO_FOCUS_BORDER
Constructors Summary
public BasicComboBoxRenderer()


      
        super();
        setOpaque(true);
        setBorder(getNoFocusBorder());
    
Methods Summary
public java.awt.ComponentgetListCellRendererComponent(javax.swing.JList list, java.lang.Object value, int index, boolean isSelected, boolean cellHasFocus)


        /**if (isSelected) {
            setBackground(UIManager.getColor("ComboBox.selectionBackground"));
            setForeground(UIManager.getColor("ComboBox.selectionForeground"));
        } else {
            setBackground(UIManager.getColor("ComboBox.background"));
            setForeground(UIManager.getColor("ComboBox.foreground"));
        }**/

        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        }
        else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }

        setFont(list.getFont());

        if (value instanceof Icon) {
            setIcon((Icon)value);
        }
        else {
            setText((value == null) ? "" : value.toString());
        }
        return this;
    
private static javax.swing.border.BordergetNoFocusBorder()

        if (System.getSecurityManager() != null) {
            return SAFE_NO_FOCUS_BORDER;
        } else {
            return noFocusBorder;
        }
    
public java.awt.DimensiongetPreferredSize()

        Dimension size;
        
        if ((this.getText() == null) || (this.getText().equals( "" ))) {
            setText( " " );
            size = super.getPreferredSize();
            setText( "" );
        }
        else {
            size = super.getPreferredSize();
        }
        
        return size;