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, override installKeyboardActions
to add actions in response to KeyStroke bindings. See the article How to Use Key Bindings
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. |
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 |
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. |
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 |
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 | Description |
---|---|
BasicComboBoxUI() |
Constructs a BasicComboBoxUI . |
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 |
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. |
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getPreferredSize, installUI, paint, uninstallUI, update
protected JComboBox<Object> comboBox
JComboBox
.protected boolean hasFocus
protected JList<Object> listBox
protected CellRendererPane currentValuePane
protected ComboPopup popup
ComboPopup
that is used to show the popup.protected Component editor
ComboBoxEditor
uses for editing.protected JButton arrowButton
protected KeyListener keyListener
protected FocusListener focusListener
protected PropertyChangeListener propertyChangeListener
protected ItemListener itemListener
protected MouseListener popupMouseListener
MouseListener
listens to events.protected MouseMotionListener popupMouseMotionListener
MouseMotionListener
listens to events.protected KeyListener popupKeyListener
KeyListener
listens to events.protected ListDataListener listDataListener
protected boolean isMinimumSizeDirty
protected Dimension cachedMinimumSize
protected boolean squareButton
protected Insets padding
public BasicComboBoxUI()
BasicComboBoxUI
.public static ComponentUI createUI(JComponent c)
BasicComboBoxUI
.c
- a componentBasicComboBoxUI
protected void installDefaults()
protected void installListeners()
protected void uninstallDefaults()
protected void uninstallListeners()
installListeners
protected ComboPopup createPopup()
ComboPopup
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.KeyListener
or nullprotected 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.FocusListener
or nullprotected ListDataListener createListDataListener()
ComboBoxModel
. If this method returns null then it will not be added to the combo box model.ListDataListener
or nullprotected 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.
ItemListener
or nullprotected 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.PropertyChangeListener
or nullprotected LayoutManager createLayoutManager()
protected ListCellRenderer<Object> createRenderer()
setRenderer
.ListCellRender
used for the combo boxprotected ComboBoxEditor createEditor()
setEditor
.ComboBoxEditor
used for the combo boxprotected void installComponents()
protected void uninstallComponents()
public void addEditor()
ComboBoxEditor
public void removeEditor()
protected void configureEditor()
protected void unconfigureEditor()
public void configureArrowButton()
public void unconfigureArrowButton()
protected JButton createArrowButton()
public boolean isPopupVisible(JComboBox<?> c)
isPopupVisible
in class ComboBoxUI
c
- a JComboBox
JComboBox
is visiblepublic void setPopupVisible(JComboBox<?> c, boolean v)
setPopupVisible
in class ComboBoxUI
c
- a JComboBox
v
- a boolean
determining the visibility of the popuppublic boolean isFocusTraversable(JComboBox<?> c)
isFocusTraversable
in class ComboBoxUI
c
- a JComboBox
JComboBox
is traversablepublic Dimension getMinimumSize(JComponent c)
getMinimumSize
in class ComponentUI
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 componentsDimension
object or null
public int getBaseline(JComponent c, int width, int height)
getBaseline
in class ComponentUI
c
- JComponent
baseline is being requested forwidth
- the width to get the baseline forheight
- the height to get the baseline forNullPointerException
- if c
is null
IllegalArgumentException
- if width or height is < 0public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
getBaselineResizeBehavior
in class ComponentUI
c
- JComponent
to return baseline resize behavior forNullPointerException
- if c
is null
protected void selectNextPossibleValue()
protected void selectPreviousPossibleValue()
protected void toggleOpenClose()
protected Rectangle rectangleForCurrentValue()
protected Insets getInsets()
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
g
- an instance of Graphics
bounds
- a bounding rectangle to render tohasFocus
- is focusedpublic void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
g
- an instance of Graphics
bounds
- a bounding rectangle to render tohasFocus
- is focusedprotected Dimension getDefaultSize()
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.
protected Dimension getSizeForComponent(Component comp)
comp
- a Component
to checkprotected void installKeyboardActions()
protected void uninstallKeyboardActions()
© 1993, 2023, 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/21/docs/api/java.desktop/javax/swing/plaf/basic/BasicComboBoxUI.html