This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.swing.plaf.basic
class BasicComboBoxUI

java.lang.Object extended by javax.swing.plaf.ComponentUI extended by javax.swing.plaf.ComboBoxUI extended by javax.swing.plaf.basic.BasicComboBoxUI
Direct Known Subclasses:
MetalComboBoxUI

public class BasicComboBoxUI
extends ComboBoxUI

Basic UI implementation for JComboBox.

The combo box is a compound component which means that it is an agregate of many simpler components. This class creates and manages the listeners on the combo box and the combo box model. These listeners update the user interface in response to changes in the properties and state of the combo box.

All event handling is handled by listener classes created with the createxxxListener() methods and internal classes. You can change the behavior of this class by overriding the createxxxListener() methods and supplying your own event listeners or subclassing from the ones supplied in this class.

For adding specific actions, overide installKeyboardActions to add actions in response to KeyStroke bindings. See the article Keyboard Bindings in Swing at The Swing Connection.


Nested Class Summary
 class

           This layout manager handles the 'standard' layout of combo boxes.
 class

           This listener hides the popup when the focus is lost.
 class

           This listener watches for changes to the selection in the combo box.
 class

           This listener checks to see if the key event isn't a navigation key.
 class

           This listener watches for changes in the ComboBoxModel.
 class

           This listener watches for bound properties that have changed in the combo box.
 
Field Summary
protected JButton arrowButton
          
protected Dimension cachedMinimumSize
          
protected JComboBox comboBox
          
protected CellRendererPane currentValuePane
          
protected Component editor
          
protected FocusListener focusListener
          This protected field is implementation specific.
protected boolean hasFocus
          This protected field is implementation specific.
protected boolean isMinimumSizeDirty
          
protected ItemListener itemListener
          This protected field is implementation specific.
protected KeyListener keyListener
          This protected field is implementation specific.
protected JList listBox
          
protected ListDataListener listDataListener
          This protected field is implementation specific.
protected ComboPopup popup
          
protected KeyListener popupKeyListener
          
protected MouseListener popupMouseListener
          
protected MouseMotionListener popupMouseMotionListener
          
protected PropertyChangeListener propertyChangeListener
          This protected field is implementation specific.
 
Constructor Summary

          
 
Method Summary
 void

          This public method is implementation specific and should be private.
 void

          This public method is implementation specific and should be private.
protected void

          This protected method is implementation specific and should be private.
protected JButton

          Creates an button which will be used as the control to show or hide the popup portion of the combo box.
protected ComboBoxEditor

          Creates the default editor that will be used in editable combo boxes.
protected FocusListener

          Creates a FocusListener which will be added to the combo box.
protected ItemListener

          Creates an ItemListener which will be added to the combo box.
protected KeyListener

          Creates a KeyListener which will be added to the combo box.
protected LayoutManager

          Creates a layout manager for managing the components which make up the combo box.
protected ListDataListener

          Creates a list data listener which will be added to the ComboBoxModel.
protected ComboPopup

          Creates the popup portion of the combo box.
protected PropertyChangeListener

          Creates a PropertyChangeListener which will be added to the combo box.
protected ListCellRenderer

          Creates the default renderer that will be used in a non-editiable combo box.
static ComponentUI

          
 Accessible

          Returns the ith Accessible child of the object.
 int

          Returns the number of accessible children in the object.
 int
getBaseline(JComponent c, int width, int height)

          Returns the baseline.
 Component.BaselineResizeBehavior

          Returns an enum indicating how the baseline of the component changes as the size changes.
protected Dimension

          Return the default size of an empty display area of the combo box using the current renderer and font.
protected Dimension

          Returns the calculated size of the display area.
protected Insets

          Gets the insets from the JComboBox.
 Dimension

          Returns the specified component's maximum size appropriate for the look and feel.
 Dimension

          The minumum size is the size of the display area plus insets plus the button.
 Dimension

          Returns the specified component's preferred size appropriate for the look and feel.
protected void

          Creates and initializes the components which make up the aggregate combo box.
protected void

          Installs the default colors, default font, default renderer, and default editor into the JComboBox.
protected void

          Adds keyboard actions to the JComboBox.
protected void

          Create and install the listeners for the combo box and its model.
 void

          Configures the specified component appropriate for the look and feel.
 boolean

          Determines if the JComboBox is focus traversable.
protected boolean
isNavigationKey(int keyCode)

          Returns whether or not the supplied keyCode maps to a key that is used for navigation.
 boolean

          Tells if the popup is visible or not.
 void

          Paints the specified component appropriate for the look and feel.
 void
paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)

          Paints the currently selected item.
 void
paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)

          Paints the background of the currently selected item.
protected Rectangle

          Returns the area that is reserved for drawing the currently selected item.
 void

          This public method is implementation specific and should be private.
protected void

          Selects the next item in the list.
protected void

          Selects the previous item in the list.
 void
setPopupVisible(JComboBox c, boolean v)

          Hides the popup.
protected void

          Hides the popup if it is showing and shows the popup if it is hidden.
 void

          This public method is implementation specific and should be private.
protected void

          This protected method is implementation specific and should be private.
protected void

          The aggregate components which compise the combo box are unregistered and uninitialized.
protected void

          Uninstalls the default colors, default font, default renderer, and default editor into the JComboBox.
protected void

          Removes the focus InputMap and ActionMap.
protected void

          Remove the installed listeners from the combo box and its model.
 void

          Reverses configuration which was done on the specified component during installUI.
 
Methods inherited from class javax.swing.plaf.ComboBoxUI
isFocusTraversable, isPopupVisible, setPopupVisible
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

arrowButton

protected JButton arrowButton

cachedMinimumSize

protected Dimension cachedMinimumSize

comboBox

protected JComboBox comboBox

currentValuePane

protected CellRendererPane currentValuePane

editor

protected Component editor

focusListener

protected FocusListener focusListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.

hasFocus

protected boolean hasFocus
This protected field is implementation specific. Do not access directly or override.

isMinimumSizeDirty

protected boolean isMinimumSizeDirty

itemListener

protected ItemListener itemListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.

keyListener

protected KeyListener keyListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.

listBox

protected JList listBox

listDataListener

protected ListDataListener listDataListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.

popup

protected ComboPopup popup

popupKeyListener

protected KeyListener popupKeyListener

popupMouseListener

protected MouseListener popupMouseListener

popupMouseMotionListener

protected MouseMotionListener popupMouseMotionListener

propertyChangeListener

protected PropertyChangeListener propertyChangeListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.
Constructor Detail

BasicComboBoxUI

public BasicComboBoxUI()
Method Detail

addEditor

public void addEditor()
This public method is implementation specific and should be private. do not call or override. To implement a specific editor create a custom ComboBoxEditor


configureArrowButton

public void configureArrowButton()
This public method is implementation specific and should be private. Do not call or override.


configureEditor

protected void configureEditor()
This protected method is implementation specific and should be private. do not call or override.


createArrowButton

protected JButton createArrowButton()
Creates an button which will be used as the control to show or hide the popup portion of the combo box.

Returns:
a button which represents the popup control

createEditor

protected ComboBoxEditor createEditor()
Creates the default editor that will be used in editable combo boxes. A default editor will be used only if an editor has not been explicitly set with setEditor.

Returns:
a ComboBoxEditor used for the combo box

createFocusListener

protected FocusListener createFocusListener()
Creates a FocusListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.

Returns:
an instance of a FocusListener or null

createItemListener

protected ItemListener createItemListener()
Creates an ItemListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.

Subclasses may override this method to return instances of their own ItemEvent handlers.

Returns:
an instance of an ItemListener or null

createKeyListener

protected KeyListener createKeyListener()
Creates a KeyListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.

Returns:
an instance KeyListener or null

createLayoutManager

protected LayoutManager createLayoutManager()
Creates a layout manager for managing the components which make up the combo box.

Returns:
an instance of a layout manager

createListDataListener

protected ListDataListener createListDataListener()
Creates a list data listener which will be added to the ComboBoxModel. If this method returns null then it will not be added to the combo box model.

Returns:
an instance of a ListDataListener or null

createPopup

protected ComboPopup createPopup()
Creates the popup portion of the combo box.

Returns:
an instance of ComboPopup

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates a PropertyChangeListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.

Returns:
an instance of a PropertyChangeListener or null

createRenderer

protected ListCellRenderer createRenderer()
Creates the default renderer that will be used in a non-editiable combo box. A default renderer will used only if a renderer has not been explicitly set with setRenderer.

Returns:
a ListCellRender used for the combo box

createUI

public static ComponentUI createUI(JComponent c)
Parameters:
c

getAccessibleChild

public Accessible getAccessibleChild(JComponent c,
                                     int i)
Overrides:
getAccessibleChild in class ComponentUI
Parameters:
c
i

getAccessibleChildrenCount

public int getAccessibleChildrenCount(JComponent c)
Overrides:
getAccessibleChildrenCount in class ComponentUI
Parameters:
c

getBaseline

public int getBaseline(JComponent c,
                       int width,
                       int height)
Returns the baseline.

Overrides:
getBaseline in class ComponentUI
Parameters:
c
width
height

getBaselineResizeBehavior

public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
Returns an enum indicating how the baseline of the component changes as the size changes.

Overrides:
getBaselineResizeBehavior in class ComponentUI
Parameters:
c

getDefaultSize

protected Dimension getDefaultSize()
Return the default size of an empty display area of the combo box using the current renderer and font.

Returns:
the size of an empty display area

getDisplaySize

protected Dimension getDisplaySize()
Returns the calculated size of the display area. The display area is the portion of the combo box in which the selected item is displayed. This method will use the prototype display value if it has been set.

For combo boxes with a non trivial number of items, it is recommended to use a prototype display value to significantly speed up the display size calculation.

Returns:
the size of the display area calculated from the combo box items

getInsets

protected Insets getInsets()
Gets the insets from the JComboBox.


getMaximumSize

public Dimension getMaximumSize(JComponent c)
Overrides:
getMaximumSize in class ComponentUI
Parameters:
c

getMinimumSize

public Dimension getMinimumSize(JComponent c)
The minumum size is the size of the display area plus insets plus the button.

Overrides:
getMinimumSize in class ComponentUI
Parameters:
c

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Overrides:
getPreferredSize in class ComponentUI
Parameters:
c

installComponents

protected void installComponents()
Creates and initializes the components which make up the aggregate combo box. This method is called as part of the UI installation process.


installDefaults

protected void installDefaults()
Installs the default colors, default font, default renderer, and default editor into the JComboBox.


installKeyboardActions

protected void installKeyboardActions()
Adds keyboard actions to the JComboBox. Actions on enter and esc are already supplied. Add more actions as you need them.


installListeners

protected void installListeners()
Create and install the listeners for the combo box and its model. This method is called when the UI is installed.


installUI

public void installUI(JComponent c)
Overrides:
installUI in class ComponentUI
Parameters:
c

isFocusTraversable

public boolean isFocusTraversable(JComboBox c)
Determines if the JComboBox is focus traversable. If the JComboBox is editable this returns false, otherwise it returns true.

Overrides:
isFocusTraversable in class ComboBoxUI
Parameters:
c

isNavigationKey

protected boolean isNavigationKey(int keyCode)
Returns whether or not the supplied keyCode maps to a key that is used for navigation. This is used for optimizing key input by only passing non- navigation keys to the type-ahead mechanism. Subclasses should override this if they change the navigation keys.

Parameters:
keyCode

isPopupVisible

public boolean isPopupVisible(JComboBox c)
Tells if the popup is visible or not.

Overrides:
isPopupVisible in class ComboBoxUI
Parameters:
c

paint

public void paint(Graphics g,
                  JComponent c)
Overrides:
paint in class ComponentUI
Parameters:
g
c

paintCurrentValue

public void paintCurrentValue(Graphics g,
                              Rectangle bounds,
                              boolean hasFocus)
Paints the currently selected item.

Parameters:
g
bounds
hasFocus

paintCurrentValueBackground

public void paintCurrentValueBackground(Graphics g,
                                        Rectangle bounds,
                                        boolean hasFocus)
Paints the background of the currently selected item.

Parameters:
g
bounds
hasFocus

rectangleForCurrentValue

protected Rectangle rectangleForCurrentValue()
Returns the area that is reserved for drawing the currently selected item.


removeEditor

public void removeEditor()
This public method is implementation specific and should be private. do not call or override.


selectNextPossibleValue

protected void selectNextPossibleValue()
Selects the next item in the list. It won't change the selection if the currently selected item is already the last item.


selectPreviousPossibleValue

protected void selectPreviousPossibleValue()
Selects the previous item in the list. It won't change the selection if the currently selected item is already the first item.


setPopupVisible

public void setPopupVisible(JComboBox c,
                            boolean v)
Hides the popup.

Overrides:
setPopupVisible in class ComboBoxUI
Parameters:
c
v

toggleOpenClose

protected void toggleOpenClose()
Hides the popup if it is showing and shows the popup if it is hidden.


unconfigureArrowButton

public void unconfigureArrowButton()
This public method is implementation specific and should be private. Do not call or override.


unconfigureEditor

protected void unconfigureEditor()
This protected method is implementation specific and should be private. Do not call or override.


uninstallComponents

protected void uninstallComponents()
The aggregate components which compise the combo box are unregistered and uninitialized. This method is called as part of the UI uninstallation process.


uninstallDefaults

protected void uninstallDefaults()
Uninstalls the default colors, default font, default renderer, and default editor into the JComboBox.


uninstallKeyboardActions

protected void uninstallKeyboardActions()
Removes the focus InputMap and ActionMap.


uninstallListeners

protected void uninstallListeners()
Remove the installed listeners from the combo box and its model. The number and types of listeners removed and in this method should be the same that was added in installListeners


uninstallUI

public void uninstallUI(JComponent c)
Overrides:
uninstallUI in class ComponentUI
Parameters:
c


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.