Class BasicComboBoxUI
- Direct Known Subclasses:
-
MetalComboBoxUI
,SynthComboBoxUI
public class BasicComboBoxUI extends ComboBoxUI
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, overide installKeyboardActions
to add actions in response to KeyStroke bindings. See the article How to Use Key Bindings
Nested Class Summary
Modifier and Type | Class | Description |
---|---|---|
class |
BasicComboBoxUI.ComboBoxLayoutManager |
This layout manager handles the 'standard' layout of combo boxes. |
class |
BasicComboBoxUI.FocusHandler |
This listener hides the popup when the focus is lost. |
class |
BasicComboBoxUI.ItemHandler |
This listener watches for changes to the selection in the combo box. |
class |
BasicComboBoxUI.KeyHandler |
This listener checks to see if the key event isn't a navigation key. |
class |
BasicComboBoxUI.ListDataHandler |
This listener watches for changes in the ComboBoxModel . |
class |
BasicComboBoxUI.PropertyChangeHandler |
This listener watches for bound properties that have changed in the combo box. |
Field Summary
Modifier and Type | Field | Description |
---|---|---|
protected JButton |
arrowButton |
The arrow button that invokes the popup. |
protected Dimension |
cachedMinimumSize |
The cached minimum preferred size. |
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 @{code ComboBoxEditor} uses for editing. |
protected FocusListener |
focusListener |
This protected field is implementation specific. |
protected boolean |
hasFocus |
This protected field is implementation specific. |
protected boolean |
isMinimumSizeDirty |
The flag for recalculating the minimum preferred size. |
protected ItemListener |
itemListener |
This protected field is implementation specific. |
protected KeyListener |
keyListener |
This protected field is implementation specific. |
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. |
protected boolean |
squareButton |
Indicates whether or not the combo box button should be square. |
Constructor Summary
Constructor | Description |
---|---|
BasicComboBoxUI() |
Constructs a BasicComboBoxUI . |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void |
addEditor() |
This public method is implementation specific and should be private. |
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 |
createArrowButton() |
Creates a button which will be used as the control to show or hide the popup portion of the combo box. |
protected ComboBoxEditor |
createEditor() |
Creates the default editor that will be used in editable combo boxes. |
protected FocusListener |
createFocusListener() |
Creates a FocusListener which will be added to the combo box. |
protected ItemListener |
createItemListener() |
Creates an ItemListener which will be added to the combo box. |
protected KeyListener |
createKeyListener() |
Creates a KeyListener which will be added to the combo box. |
protected LayoutManager |
createLayoutManager() |
Creates a layout manager for managing the components which make up the combo box. |
protected ListDataListener |
createListDataListener() |
Creates a list data listener which will be added to the ComboBoxModel . |
protected ComboPopup |
createPopup() |
Creates the popup portion of the combo box. |
protected PropertyChangeListener |
createPropertyChangeListener() |
Creates a PropertyChangeListener which will be added to the combo box. |
protected ListCellRenderer<Object> |
createRenderer() |
Creates the default renderer that will be used in a non-editiable combo box. |
static ComponentUI |
createUI |
Constructs a new instance of BasicComboBoxUI . |
int |
getBaseline |
Returns the baseline. |
Component.BaselineResizeBehavior |
getBaselineResizeBehavior |
Returns an enum indicating how the baseline of the component changes as the size changes. |
protected Dimension |
getDefaultSize() |
Return the default size of an empty display area of the combo box using the current renderer and font. |
protected Dimension |
getDisplaySize() |
Returns the calculated size of the display area. |
protected Insets |
getInsets() |
Gets the insets from the JComboBox. |
Dimension |
getMinimumSize |
The minimum size is the size of the display area plus insets plus the button. |
protected Dimension |
getSizeForComponent |
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. |
boolean |
isFocusTraversable |
Determines if the JComboBox is focus traversable. |
protected boolean |
isNavigationKey |
Returns whether or not the supplied keyCode maps to a key that is used for navigation. |
boolean |
isPopupVisible |
Tells if the popup is visible or not. |
void |
paintCurrentValue |
Paints the currently selected item. |
void |
paintCurrentValueBackground |
Paints the background of the currently selected item. |
protected Rectangle |
rectangleForCurrentValue() |
Returns the area that is reserved for drawing the currently selected item. |
void |
removeEditor() |
This public method is implementation specific and should be private. |
protected void |
selectNextPossibleValue() |
Selects the next item in the list. |
protected void |
selectPreviousPossibleValue() |
Selects the previous item in the list. |
void |
setPopupVisible |
Hides the popup. |
protected void |
toggleOpenClose() |
Hides the popup if it is showing and shows the popup if it is hidden. |
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. |
Methods declared in class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getPreferredSize, installUI, paint, uninstallUI, update
Field Details
comboBox
protected JComboBox<Object> comboBox
JComboBox
.hasFocus
protected boolean hasFocus
listBox
protected JList<Object> listBox
currentValuePane
protected CellRendererPane currentValuePane
popup
protected ComboPopup popup
ComboPopup
that is used to show the popup.editor
protected Component editor
arrowButton
protected JButton arrowButton
keyListener
protected KeyListener keyListener
- See Also:
focusListener
protected FocusListener focusListener
- See Also:
propertyChangeListener
protected PropertyChangeListener propertyChangeListener
- See Also:
itemListener
protected ItemListener itemListener
- See Also:
popupMouseListener
protected MouseListener popupMouseListener
MouseListener
listens to events.popupMouseMotionListener
protected MouseMotionListener popupMouseMotionListener
MouseMotionListener
listens to events.popupKeyListener
protected KeyListener popupKeyListener
KeyListener
listens to events.listDataListener
protected ListDataListener listDataListener
- See Also:
isMinimumSizeDirty
protected boolean isMinimumSizeDirty
cachedMinimumSize
protected Dimension cachedMinimumSize
squareButton
protected boolean squareButton
- Since:
- 1.7
padding
protected Insets padding
- Since:
- 1.7
Constructor Details
BasicComboBoxUI
public BasicComboBoxUI()
BasicComboBoxUI
.Method Details
createUI
public static ComponentUI createUI(JComponent c)
BasicComboBoxUI
.- Parameters:
-
c
- a component - Returns:
- a new instance of
BasicComboBoxUI
installDefaults
protected void installDefaults()
installListeners
protected void installListeners()
uninstallDefaults
protected void uninstallDefaults()
uninstallListeners
protected void uninstallListeners()
installListeners
createPopup
protected ComboPopup createPopup()
- Returns:
- an instance of
ComboPopup
- See Also:
createKeyListener
protected KeyListener createKeyListener()
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
createFocusListener
protected FocusListener createFocusListener()
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
createListDataListener
protected ListDataListener createListDataListener()
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
createItemListener
protected ItemListener createItemListener()
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
createPropertyChangeListener
protected PropertyChangeListener createPropertyChangeListener()
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
createLayoutManager
protected LayoutManager createLayoutManager()
- Returns:
- an instance of a layout manager
createRenderer
protected ListCellRenderer<Object> createRenderer()
setRenderer
.- Returns:
- a
ListCellRender
used for the combo box - See Also:
createEditor
protected ComboBoxEditor createEditor()
setEditor
.- Returns:
- a
ComboBoxEditor
used for the combo box - See Also:
installComponents
protected void installComponents()
uninstallComponents
protected void uninstallComponents()
addEditor
public void addEditor()
ComboBoxEditor
removeEditor
public void removeEditor()
- See Also:
configureEditor
protected void configureEditor()
- See Also:
unconfigureEditor
protected void unconfigureEditor()
- See Also:
configureArrowButton
public void configureArrowButton()
- See Also:
unconfigureArrowButton
public void unconfigureArrowButton()
- See Also:
createArrowButton
protected JButton createArrowButton()
- Returns:
- a button which represents the popup control
isPopupVisible
public boolean isPopupVisible(JComboBox<?> c)
- Specified by:
-
isPopupVisible
in classComboBoxUI
- Parameters:
-
c
- aJComboBox
- Returns:
- true if popup of the
JComboBox
is visible
setPopupVisible
public void setPopupVisible(JComboBox<?> c, boolean v)
- Specified by:
-
setPopupVisible
in classComboBoxUI
- Parameters:
-
c
- aJComboBox
-
v
- aboolean
determining the visibilty of the popup
isFocusTraversable
public boolean isFocusTraversable(JComboBox<?> c)
- Specified by:
-
isFocusTraversable
in classComboBoxUI
- Parameters:
-
c
- aJComboBox
- Returns:
- true if the given
JComboBox
is traversable
getMinimumSize
public Dimension getMinimumSize(JComponent c)
- Overrides:
-
getMinimumSize
in classComponentUI
- Parameters:
-
c
- the component whose minimum size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components - Returns:
- a
Dimension
object ornull
- See Also:
getBaseline
public int getBaseline(JComponent c, int width, int height)
- Overrides:
-
getBaseline
in classComponentUI
- Parameters:
-
c
-JComponent
baseline is being requested for -
width
- the width to get the baseline for -
height
- the height to get the baseline for - Returns:
- baseline or a value < 0 indicating there is no reasonable baseline
- Throws:
-
NullPointerException
- ifc
isnull
-
IllegalArgumentException
- if width or height is < 0 - Since:
- 1.6
- See Also:
getBaselineResizeBehavior
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
- Overrides:
-
getBaselineResizeBehavior
in classComponentUI
- Parameters:
-
c
-JComponent
to return baseline resize behavior for - Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
-
NullPointerException
- ifc
isnull
- Since:
- 1.6
- See Also:
selectNextPossibleValue
protected void selectNextPossibleValue()
selectPreviousPossibleValue
protected void selectPreviousPossibleValue()
toggleOpenClose
protected void toggleOpenClose()
rectangleForCurrentValue
protected Rectangle rectangleForCurrentValue()
- Returns:
- the area that is reserved for drawing the currently selected item
getInsets
protected Insets getInsets()
- Returns:
- the insets
paintCurrentValue
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
- Parameters:
-
g
- an instance ofGraphics
-
bounds
- a bounding rectangle to render to -
hasFocus
- is focused
paintCurrentValueBackground
public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
- Parameters:
-
g
- an instance ofGraphics
-
bounds
- a bounding rectangle to render to -
hasFocus
- is focused
getDefaultSize
protected Dimension getDefaultSize()
- Returns:
- the size of an empty display area
- See Also:
getDisplaySize
protected Dimension getDisplaySize()
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
- See Also:
getSizeForComponent
protected Dimension getSizeForComponent(Component comp)
- Parameters:
-
comp
- aComponent
to check - Returns:
- size of the component
- Since:
- 1.7
installKeyboardActions
protected void installKeyboardActions()
uninstallKeyboardActions
protected void uninstallKeyboardActions()
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/plaf/basic/BasicComboBoxUI.html