- java.lang.Object
- 
- javax.swing.plaf.ComponentUI
- 
- javax.swing.plaf.ComboBoxUI
- 
- javax.swing.plaf.basic.BasicComboBoxUI
 
 
 
- 
- Direct Known Subclasses:
- MetalComboBoxUI,- SynthComboBoxUI
 
 public class BasicComboBoxUI extends ComboBoxUI 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 thecreatexxxListener()methods and supplying your own event listeners or subclassing from the ones supplied in this class.For adding specific actions, overide installKeyboardActionsto add actions in response to KeyStroke bindings. See the article How to Use Key Bindings
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description classBasicComboBoxUI.ComboBoxLayoutManagerThis layout manager handles the 'standard' layout of combo boxes.classBasicComboBoxUI.FocusHandlerThis listener hides the popup when the focus is lost.classBasicComboBoxUI.ItemHandlerThis listener watches for changes to the selection in the combo box.classBasicComboBoxUI.KeyHandlerThis listener checks to see if the key event isn't a navigation key.classBasicComboBoxUI.ListDataHandlerThis listener watches for changes in theComboBoxModel.classBasicComboBoxUI.PropertyChangeHandlerThis listener watches for bound properties that have changed in the combo box.
 - 
Field SummaryFields Modifier and Type Field Description protected JButtonarrowButtonThe arrow button that invokes the popup.protected DimensioncachedMinimumSizeThe cached minimum preferred size.protected JComboBox<Object>comboBoxThe instance ofJComboBox.protected CellRendererPanecurrentValuePaneUsed to render the currently selected item in the combo box.protected ComponenteditorThe Component that the @{code ComboBoxEditor} uses for editing.protected FocusListenerfocusListenerThis protected field is implementation specific.protected booleanhasFocusThis protected field is implementation specific.protected booleanisMinimumSizeDirtyThe flag for recalculating the minimum preferred size.protected ItemListeneritemListenerThis protected field is implementation specific.protected KeyListenerkeyListenerThis protected field is implementation specific.protected JList<Object>listBoxThis list is for drawing the current item in the combo box.protected ListDataListenerlistDataListenerThis protected field is implementation specific.protected InsetspaddingIf specified, these insets act as padding around the cell renderer when laying out and painting the "selected" item in the combo box.protected ComboPopuppopupThe implementation ofComboPopupthat is used to show the popup.protected KeyListenerpopupKeyListenerTheKeyListenerlistens to events.protected MouseListenerpopupMouseListenerTheMouseListenerlistens to events.protected MouseMotionListenerpopupMouseMotionListenerTheMouseMotionListenerlistens to events.protected PropertyChangeListenerpropertyChangeListenerThis protected field is implementation specific.protected booleansquareButtonIndicates whether or not the combo box button should be square.
 - 
Constructor SummaryConstructors Constructor Description BasicComboBoxUI()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEditor()This public method is implementation specific and should be private.voidconfigureArrowButton()This public method is implementation specific and should be private.protected voidconfigureEditor()This protected method is implementation specific and should be private.protected JButtoncreateArrowButton()Creates a button which will be used as the control to show or hide the popup portion of the combo box.protected ComboBoxEditorcreateEditor()Creates the default editor that will be used in editable combo boxes.protected FocusListenercreateFocusListener()Creates aFocusListenerwhich will be added to the combo box.protected ItemListenercreateItemListener()Creates anItemListenerwhich will be added to the combo box.protected KeyListenercreateKeyListener()Creates aKeyListenerwhich will be added to the combo box.protected LayoutManagercreateLayoutManager()Creates a layout manager for managing the components which make up the combo box.protected ListDataListenercreateListDataListener()Creates a list data listener which will be added to theComboBoxModel.protected ComboPopupcreatePopup()Creates the popup portion of the combo box.protected PropertyChangeListenercreatePropertyChangeListener()Creates aPropertyChangeListenerwhich 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 ComponentUIcreateUI(JComponent c)Constructs a new instance ofBasicComboBoxUI.intgetBaseline(JComponent c, int width, int height)Returns the baseline.Component.BaselineResizeBehaviorgetBaselineResizeBehavior(JComponent c)Returns an enum indicating how the baseline of the component changes as the size changes.protected DimensiongetDefaultSize()Return the default size of an empty display area of the combo box using the current renderer and font.protected DimensiongetDisplaySize()Returns the calculated size of the display area.protected InsetsgetInsets()Gets the insets from the JComboBox.DimensiongetMinimumSize(JComponent c)The minimum size is the size of the display area plus insets plus the button.protected DimensiongetSizeForComponent(Component comp)Returns the size a component would have if used as a cell renderer.protected voidinstallComponents()Creates and initializes the components which make up the aggregate combo box.protected voidinstallDefaults()Installs the default colors, default font, default renderer, and default editor into the JComboBox.protected voidinstallKeyboardActions()Adds keyboard actions to the JComboBox.protected voidinstallListeners()Creates and installs listeners for the combo box and its model.booleanisFocusTraversable(JComboBox<?> c)Determines if the JComboBox is focus traversable.protected booleanisNavigationKey(int keyCode)Returns whether or not the supplied keyCode maps to a key that is used for navigation.booleanisPopupVisible(JComboBox<?> c)Tells if the popup is visible or not.voidpaintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)Paints the currently selected item.voidpaintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)Paints the background of the currently selected item.protected RectanglerectangleForCurrentValue()Returns the area that is reserved for drawing the currently selected item.voidremoveEditor()This public method is implementation specific and should be private.protected voidselectNextPossibleValue()Selects the next item in the list.protected voidselectPreviousPossibleValue()Selects the previous item in the list.voidsetPopupVisible(JComboBox<?> c, boolean v)Hides the popup.protected voidtoggleOpenClose()Hides the popup if it is showing and shows the popup if it is hidden.voidunconfigureArrowButton()This public method is implementation specific and should be private.protected voidunconfigureEditor()This protected method is implementation specific and should be private.protected voiduninstallComponents()The aggregate components which comprise the combo box are unregistered and uninitialized.protected voiduninstallDefaults()Uninstalls the default colors, default font, default renderer, and default editor from the combo box.protected voiduninstallKeyboardActions()Removes the focus InputMap and ActionMap.protected voiduninstallListeners()Removes the installed listeners from the combo box and its model.- 
Methods declared in class javax.swing.plaf.ComponentUIcontains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getPreferredSize, installUI, paint, uninstallUI, update
 
- 
 
- 
- 
- 
Field Detail- 
hasFocusprotected boolean hasFocus This protected field is implementation specific. Do not access directly or override.
 - 
currentValuePaneprotected CellRendererPane currentValuePane Used to render the currently selected item in the combo box. It doesn't have anything to do with the popup's rendering.
 - 
popupprotected ComboPopup popup The implementation ofComboPopupthat is used to show the popup.
 - 
editorprotected Component editor The Component that the @{code ComboBoxEditor} uses for editing.
 - 
arrowButtonprotected JButton arrowButton The arrow button that invokes the popup.
 - 
keyListenerprotected KeyListener keyListener This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.- See Also:
- createKeyListener()
 
 - 
focusListenerprotected FocusListener focusListener This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.- See Also:
- createFocusListener()
 
 - 
propertyChangeListenerprotected PropertyChangeListener propertyChangeListener This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.- See Also:
- createPropertyChangeListener()
 
 - 
itemListenerprotected ItemListener itemListener This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.- See Also:
- createItemListener()
 
 - 
popupMouseListenerprotected MouseListener popupMouseListener TheMouseListenerlistens to events.
 - 
popupMouseMotionListenerprotected MouseMotionListener popupMouseMotionListener TheMouseMotionListenerlistens to events.
 - 
popupKeyListenerprotected KeyListener popupKeyListener TheKeyListenerlistens to events.
 - 
listDataListenerprotected ListDataListener listDataListener This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.- See Also:
- createListDataListener()
 
 - 
isMinimumSizeDirtyprotected boolean isMinimumSizeDirty The flag for recalculating the minimum preferred size.
 - 
cachedMinimumSizeprotected Dimension cachedMinimumSize The cached minimum preferred size.
 - 
squareButtonprotected boolean squareButton Indicates whether or not the combo box button should be square. If square, then the width and height are equal, and are both set to the height of the combo minus appropriate insets.- Since:
- 1.7
 
 - 
paddingprotected 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. These insets add to those specified by the cell renderer.- Since:
- 1.7
 
 
- 
 - 
Method Detail- 
createUIpublic static ComponentUI createUI(JComponent c) Constructs a new instance ofBasicComboBoxUI.- Parameters:
- c- a component
- Returns:
- a new instance of BasicComboBoxUI
 
 - 
installDefaultsprotected void installDefaults() Installs the default colors, default font, default renderer, and default editor into the JComboBox.
 - 
installListenersprotected void installListeners() Creates and installs listeners for the combo box and its model. This method is called when the UI is installed.
 - 
uninstallDefaultsprotected void uninstallDefaults() Uninstalls the default colors, default font, default renderer, and default editor from the combo box.
 - 
uninstallListenersprotected void uninstallListeners() Removes 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 ininstallListeners
 - 
createPopupprotected ComboPopup createPopup() Creates the popup portion of the combo box.- Returns:
- an instance of ComboPopup
- See Also:
- ComboPopup
 
 - 
createKeyListenerprotected KeyListener createKeyListener() Creates aKeyListenerwhich 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 KeyListeneror null
 
 - 
createFocusListenerprotected FocusListener createFocusListener() Creates aFocusListenerwhich 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 FocusListeneror null
 
 - 
createListDataListenerprotected ListDataListener createListDataListener() Creates a list data listener which will be added to theComboBoxModel. If this method returns null then it will not be added to the combo box model.- Returns:
- an instance of a ListDataListeneror null
 
 - 
createItemListenerprotected ItemListener createItemListener() Creates anItemListenerwhich 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 ItemListeneror null
 
 - 
createPropertyChangeListenerprotected PropertyChangeListener createPropertyChangeListener() Creates aPropertyChangeListenerwhich 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 PropertyChangeListeneror null
 
 - 
createLayoutManagerprotected LayoutManager createLayoutManager() Creates a layout manager for managing the components which make up the combo box.- Returns:
- an instance of a layout manager
 
 - 
createRendererprotected ListCellRenderer<Object> 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 withsetRenderer.- Returns:
- a ListCellRenderused for the combo box
- See Also:
- JComboBox.setRenderer(javax.swing.ListCellRenderer<? super E>)
 
 - 
createEditorprotected 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 withsetEditor.- Returns:
- a ComboBoxEditorused for the combo box
- See Also:
- JComboBox.setEditor(javax.swing.ComboBoxEditor)
 
 - 
installComponentsprotected 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.
 - 
uninstallComponentsprotected void uninstallComponents() The aggregate components which comprise the combo box are unregistered and uninitialized. This method is called as part of the UI uninstallation process.
 - 
addEditorpublic void addEditor() This public method is implementation specific and should be private. do not call or override. To implement a specific editor create a customComboBoxEditor
 - 
removeEditorpublic void removeEditor() This public method is implementation specific and should be private. do not call or override.- See Also:
- addEditor()
 
 - 
configureEditorprotected void configureEditor() This protected method is implementation specific and should be private. do not call or override.- See Also:
- addEditor()
 
 - 
unconfigureEditorprotected void unconfigureEditor() This protected method is implementation specific and should be private. Do not call or override.- See Also:
- addEditor()
 
 - 
configureArrowButtonpublic void configureArrowButton() This public method is implementation specific and should be private. Do not call or override.- See Also:
- createArrowButton()
 
 - 
unconfigureArrowButtonpublic void unconfigureArrowButton() This public method is implementation specific and should be private. Do not call or override.- See Also:
- createArrowButton()
 
 - 
createArrowButtonprotected JButton createArrowButton() Creates a 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
 
 - 
isPopupVisiblepublic boolean isPopupVisible(JComboBox<?> c) Tells if the popup is visible or not.- Specified by:
- isPopupVisiblein class- ComboBoxUI
- Parameters:
- c- a- JComboBox
- Returns:
- true if popup of the JComboBoxis visible
 
 - 
setPopupVisiblepublic void setPopupVisible(JComboBox<?> c, boolean v) Hides the popup.- Specified by:
- setPopupVisiblein class- ComboBoxUI
- Parameters:
- c- a- JComboBox
- v- a- booleandetermining the visibilty of the popup
 
 - 
isFocusTraversablepublic boolean isFocusTraversable(JComboBox<?> c) Determines if the JComboBox is focus traversable. If the JComboBox is editable this returns false, otherwise it returns true.- Specified by:
- isFocusTraversablein class- ComboBoxUI
- Parameters:
- c- a- JComboBox
- Returns:
- true if the given JComboBoxis traversable
 
 - 
getMinimumSizepublic Dimension getMinimumSize(JComponent c) The minimum size is the size of the display area plus insets plus the button.- Overrides:
- getMinimumSizein class- ComponentUI
- 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 Dimensionobject ornull
- See Also:
- JComponent.getMinimumSize(),- LayoutManager.minimumLayoutSize(java.awt.Container),- ComponentUI.getPreferredSize(javax.swing.JComponent)
 
 - 
getBaselinepublic int getBaseline(JComponent c, int width, int height) Returns the baseline.- Overrides:
- getBaselinein class- ComponentUI
- Parameters:
- c-- JComponentbaseline 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- if- cis- null
- IllegalArgumentException- if width or height is < 0
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
 - 
getBaselineResizeBehaviorpublic Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) Returns an enum indicating how the baseline of the component changes as the size changes.- Overrides:
- getBaselineResizeBehaviorin class- ComponentUI
- Parameters:
- c-- JComponentto return baseline resize behavior for
- Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
- NullPointerException- if- cis- null
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
 - 
isNavigationKeyprotected 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- a key code
- Returns:
- trueif the supplied- keyCodemaps to a navigation key
 
 - 
selectNextPossibleValueprotected 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.
 - 
selectPreviousPossibleValueprotected 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.
 - 
toggleOpenCloseprotected void toggleOpenClose() Hides the popup if it is showing and shows the popup if it is hidden.
 - 
rectangleForCurrentValueprotected Rectangle rectangleForCurrentValue() Returns the area that is reserved for drawing the currently selected item.- Returns:
- the area that is reserved for drawing the currently selected item
 
 - 
getInsetsprotected Insets getInsets() Gets the insets from the JComboBox.- Returns:
- the insets
 
 - 
paintCurrentValuepublic void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) Paints the currently selected item.- Parameters:
- g- an instance of- Graphics
- bounds- a bounding rectangle to render to
- hasFocus- is focused
 
 - 
paintCurrentValueBackgroundpublic void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus) Paints the background of the currently selected item.- Parameters:
- g- an instance of- Graphics
- bounds- a bounding rectangle to render to
- hasFocus- is focused
 
 - 
getDefaultSizeprotected 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
- See Also:
- getDisplaySize()
 
 - 
getDisplaySizeprotected 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
- See Also:
- JComboBox.setPrototypeDisplayValue(E)
 
 - 
getSizeForComponentprotected Dimension getSizeForComponent(Component comp) Returns the size a component would have if used as a cell renderer.- Parameters:
- comp- a- Componentto check
- Returns:
- size of the component
- Since:
- 1.7
 
 - 
installKeyboardActionsprotected void installKeyboardActions() Adds keyboard actions to the JComboBox. Actions on enter and esc are already supplied. Add more actions as you need them.
 - 
uninstallKeyboardActionsprotected void uninstallKeyboardActions() Removes the focus InputMap and ActionMap.
 
- 
 
-