APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.plaf.basic

public Class BasicComboBoxUI

extends ComboBoxUI
Class Inheritance
Known Direct Subclasses
javax.swing.plaf.metal.MetalComboBoxUI, javax.swing.plaf.synth.SynthComboBoxUI, com.sun.java.swing.plaf.motif.MotifComboBoxUI
Imports
java.awt.*, java.awt.event.*, javax.swing.*, javax.accessibility.*, javax.swing.plaf.*, javax.swing.text.*, javax.swing.event.*, java.beans.PropertyChangeListener, .PropertyChangeEvent, sun.swing.DefaultLookup, .SwingUtilities2, .UIAction

Basic UI implementation for JComboBox.

The combo box is a compound component which means that it is an aggregate 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, override installKeyboardActions to add actions in response to KeyStroke bindings. See the article How to Use Key Bindings

Authors
Arnaud Weber, Tom Santos, Mark Davidson

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public class
BasicComboBoxUI.ComboBoxLayoutManager

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

pack-priv class
public class
BasicComboBoxUI.FocusHandler

This listener hides the popup when the focus is lost.

private class
public class
BasicComboBoxUI.ItemHandler

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

public class
BasicComboBoxUI.KeyHandler

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

public class
BasicComboBoxUI.ListDataHandler

This listener watches for changes in the ComboBoxModel.

public class
BasicComboBoxUI.PropertyChangeHandler

This listener watches for bound properties that have changed in the combo box.

Field Summary

Modifier and TypeField and Description
protected JButton
arrowButton

The arrow button that invokes the popup.

private Dimension
protected Dimension
cachedMinimumSize

The cached minimum preferred size.

private static final ListCellRenderer<Object>
protected JComboBox<Object>
comboBox

The instance of JComboBox.

protected CellRendererPane
currentValuePane

Used to render the currently selected item in the combo box.

protected Component
editor

The Component that the ComboBoxEditor uses for editing.

protected FocusListener
focusListener

This protected field is implementation specific.

private BasicComboBoxUI.Handler
handler

Implements all the Listeners needed by this class, all existing listeners redirect to it.

protected boolean
hasFocus

This protected field is implementation specific.

pack-priv static final StringBuffer
private static final String
private boolean
protected boolean
isMinimumSizeDirty

The flag for recalculating the minimum preferred size.

private boolean
protected ItemListener
itemListener

This protected field is implementation specific.

protected KeyListener
keyListener

This protected field is implementation specific.

pack-priv JComboBox.KeySelectionManager
keySelectionManager

The default key selection manager

private long
lastTime

This is tricky, this variables is needed for DefaultKeySelectionManager to take into account time factor.

protected JList<Object>
listBox

This list is for drawing the current item in the combo box.

protected ListDataListener
listDataListener

This protected field is implementation specific.

protected Insets
padding

If specified, these insets act as padding around the cell renderer when laying out and painting the "selected" item in the combo box.

protected ComboPopup
popup

The implementation of ComboPopup that is used to show the popup.

protected KeyListener
popupKeyListener

The KeyListener listens to events.

protected MouseListener
popupMouseListener

The MouseListener listens to events.

protected MouseMotionListener
popupMouseMotionListener

The MouseMotionListener listens to events.

protected PropertyChangeListener
propertyChangeListener

This protected field is implementation specific.

private boolean
sameBaseline

Whether or not all cells have the same baseline.

protected boolean
squareButton

Indicates whether or not the combo box button should be square.

private long
private long
timeFactor

The time factor to treat the series of typed alphanumeric key as prefix for first letter navigation.

Constructor Summary

AccessConstructor and Description
public
BasicComboBoxUI()

Constructs a BasicComboBoxUI.

Method Summary

Modifier and TypeMethod and Description
public void
addEditor()

This public method is implementation specific and should be private.

public void
configureArrowButton()

This public method is implementation specific and should be private.

protected void
configureEditor()

This protected method is implementation specific and should be private.

protected JButton

Returns:

a button which represents the popup control
createArrowButton
()

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

protected ComboBoxEditor

Returns:

a ComboBoxEditor used for the combo box
createEditor
()

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

protected FocusListener

Returns:

an instance of a FocusListener or null
createFocusListener
()

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

protected ItemListener

Returns:

an instance of an ItemListener or null
createItemListener
()

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

protected KeyListener

Returns:

an instance KeyListener or null
createKeyListener
()

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

protected LayoutManager

Returns:

an instance of a layout manager
createLayoutManager
()

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

protected ListDataListener

Returns:

an instance of a ListDataListener or null
createListDataListener
()

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

protected ComboPopup

Returns:

an instance of ComboPopup
createPopup
()

Creates the popup portion of the combo box.

protected PropertyChangeListener

Returns:

an instance of a PropertyChangeListener or null
createPropertyChangeListener
()

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

protected ListCellRenderer<Object>

Returns:

a ListCellRender used for the combo box
createRenderer
()

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

public static ComponentUI

Returns:

a new instance of BasicComboBoxUI
createUI
(JComponent
a component
c
)

Hides javax.swing.plaf.ComponentUI.createUI.

Constructs a new instance of BasicComboBoxUI.

public Accessible
getAccessibleChild(JComponent c, int i)

Overrides javax.swing.plaf.ComponentUI.getAccessibleChild.

Returns the ith Accessible child of the object.

public int
getAccessibleChildrenCount(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getAccessibleChildrenCount.

Returns the number of accessible children in the object.

public int
getBaseline(JComponent c, int width, int height)

Overrides javax.swing.plaf.ComponentUI.getBaseline.

Returns the baseline.

public Component.BaselineResizeBehavior
getBaselineResizeBehavior(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getBaselineResizeBehavior.

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

private static ListCellRenderer<Object>
protected Dimension

Returns:

the size of an empty display area
getDefaultSize
()

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

protected Dimension

Returns:

the size of the display area calculated from the combo box items
getDisplaySize
()

Returns the calculated size of the display area.

private BasicComboBoxUI.Handler
getHandler()

Returns the shared listener.

pack-priv InputMap
getInputMap(int condition)

protected Insets

Returns:

the insets
getInsets
()

Gets the insets from the JComboBox.

public Dimension
getMaximumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMaximumSize.

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

public Dimension
getMinimumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMinimumSize.

The minimum size is the size of the display area plus insets plus the button.

public Dimension
getPreferredSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getPreferredSize.

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

protected Dimension

Returns:

size of the component
getSizeForComponent
(Component
a Component to check
comp
)

Returns the size a component would have if used as a cell renderer.

protected void
installComponents()

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

protected void
installDefaults()

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

protected void
installKeyboardActions()

Adds keyboard actions to the JComboBox.

protected void
installListeners()

Creates and installs listeners for the combo box and its model.

public void
installUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.installUI.

Configures the specified component appropriately for the look and feel.

public boolean
isFocusTraversable(JComboBox<?> c)

Implements abstract javax.swing.plaf.ComboBoxUI.isFocusTraversable.

Determines if the JComboBox is focus traversable.

protected boolean

Returns:

true if the supplied keyCode maps to a navigation key
isNavigationKey
(int
a key code
keyCode
)

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

private boolean
isNavigationKey(int keyCode, int modifiers)

public boolean
isPopupVisible(JComboBox<?> c)

Implements abstract javax.swing.plaf.ComboBoxUI.isPopupVisible.

Tells if the popup is visible or not.

pack-priv boolean
pack-priv static void
loadActionMap(LazyActionMap map)

Populates ComboBox's actions.

public void
paint(Graphics g, JComponent c)

Overrides javax.swing.plaf.ComponentUI.paint.

Paints the specified component appropriately for the look and feel.

public void
paintCurrentValue(Graphics
an instance of Graphics
g
,
Rectangle
a bounding rectangle to render to
bounds
,
boolean
is focused
hasFocus
)

Paints the currently selected item.

public void
paintCurrentValueBackground(Graphics
an instance of Graphics
g
,
Rectangle
a bounding rectangle to render to
bounds
,
boolean
is focused
hasFocus
)

Paints the background of the currently selected item.

protected Rectangle

Returns:

the area that is reserved for drawing the currently selected item
rectangleForCurrentValue
()

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

public void
removeEditor()

This public method is implementation specific and should be private.

pack-priv void
repaintCurrentValue()

Repaint the currently selected item.

protected void
selectNextPossibleValue()

Selects the next item in the list.

protected void
selectPreviousPossibleValue()

Selects the previous item in the list.

public void
setPopupVisible(JComboBox<?> c, boolean v)

Implements abstract javax.swing.plaf.ComboBoxUI.setPopupVisible.

Hides the popup.

protected void
toggleOpenClose()

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

public void
unconfigureArrowButton()

This public method is implementation specific and should be private.

protected void
unconfigureEditor()

This protected method is implementation specific and should be private.

protected void
uninstallComponents()

The aggregate components which comprise the combo box are unregistered and uninitialized.

protected void
uninstallDefaults()

Uninstalls the default colors, default font, default renderer, and default editor from the combo box.

protected void
uninstallKeyboardActions()

Removes the focus InputMap and ActionMap.

protected void
uninstallListeners()

Removes the installed listeners from the combo box and its model.

public void
uninstallUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.uninstallUI.

Reverses configuration which was done on the specified component during installUI.

private void