javax.swing.plaf.basic

Class BasicComboBoxUI

public class BasicComboBoxUI extends ComboBoxUI

A UI delegate for the {@link JComboBox} component.
Nested Class Summary
classBasicComboBoxUI.ComboBoxLayoutManager
A {@link LayoutManager} used to position the sub-components of the {@link JComboBox}.
classBasicComboBoxUI.FocusHandler
Handles focus changes occuring in the combo box.
classBasicComboBoxUI.ItemHandler
Handles {@link ItemEvent}s fired by the {@link JComboBox} when its selected item changes.
classBasicComboBoxUI.KeyHandler
KeyHandler handles key events occuring while JComboBox has focus.
classBasicComboBoxUI.ListDataHandler
Handles the changes occurring in the JComboBox's data model.
classBasicComboBoxUI.PropertyChangeHandler
Handles {@link PropertyChangeEvent}s fired by the {@link JComboBox}.
Field Summary
protected JButtonarrowButton
The arrow button that is displayed in the right side of JComboBox.
protected DimensioncachedMinimumSize
The current minimum size if isMinimumSizeDirty is false.
protected JComboBoxcomboBox
The combo box represented by this UI delegate.
protected CellRendererPanecurrentValuePane
Used to render the combo box values.
protected Componenteditor
The component that is responsible for displaying/editing the selected item of the combo box.
protected FocusListenerfocusListener
A listener listening to focus events occurring in the {@link JComboBox}.
protected booleanhasFocus
A flag indicating whether JComboBox currently has the focus.
protected booleanisMinimumSizeDirty
Indicates whether or not the cachedMinimumSize field is valid or not.
protected ItemListeneritemListener
A listener listening to item events fired by the {@link JComboBox}.
protected KeyListenerkeyListener
A listener listening to key events that occur while {@link JComboBox} has the focus.
protected JListlistBox
List used when rendering selected item of the combo box.
protected ListDataListenerlistDataListener
ListDataListener listening to JComboBox model
protected ComboPopuppopup
Popup list containing the combo box's menu items.
protected KeyListenerpopupKeyListener
protected MouseListenerpopupMouseListener
protected MouseMotionListenerpopupMouseMotionListener
protected PropertyChangeListenerpropertyChangeListener
Listener listening to changes in the bound properties of JComboBox
Constructor Summary
BasicComboBoxUI()
Creates a new BasicComboBoxUI object.
Method Summary
voidaddEditor()
Adds the current editor to the combo box.
voidconfigureArrowButton()
Configures the arrow button.
protected voidconfigureEditor()
Configures the editor for this combo box.
protected JButtoncreateArrowButton()
Creates an arrow button for this {@link JComboBox}.
protected ComboBoxEditorcreateEditor()
Creates the component that will be responsible for displaying/editing the selected item in the combo box.
protected FocusListenercreateFocusListener()
Creates the {@link FocusListener} that will listen to changes in this JComboBox's focus.
protected ItemListenercreateItemListener()
Creates an {@link ItemListener} that will listen to the changes in the JComboBox's selection.
protected KeyListenercreateKeyListener()
Creates a {@link KeyListener} to listen to key events.
protected LayoutManagercreateLayoutManager()
Creates and returns a layout manager for the combo box.
protected ListDataListenercreateListDataListener()
Creates a {@link ListDataListener} to listen to the combo box's data model.
protected ComboPopupcreatePopup()
Creates the popup that will contain list of combo box's items.
protected PropertyChangeListenercreatePropertyChangeListener()
Creates a {@link PropertyChangeListener} to listen to the changes in the JComboBox's bound properties.
protected ListCellRenderercreateRenderer()
Creates a component that will be responsible for rendering the selected component in the combo box.
static ComponentUIcreateUI(JComponent c)
A factory method to create a UI delegate for the given {@link JComponent}, which should be a {@link JComboBox}.
AccessiblegetAccessibleChild(JComponent c, int i)
Returns the accessible child with the specified index.
intgetAccessibleChildrenCount(JComponent c)
Returns the number of accessible children of the combobox.
protected DimensiongetDefaultSize()
Returns the default size for the display area of a combo box that does not contain any elements.
protected DimensiongetDisplaySize()
Returns the size of the display area for the combo box.
protected InsetsgetInsets()
Returns the insets of the current border.
DimensiongetMaximumSize(JComponent c)
Returns the maximum size for this {@link JComboBox} for this look and feel.
DimensiongetMinimumSize(JComponent c)
Returns the minimum size for this {@link JComboBox} for this look and feel.
DimensiongetPreferredSize(JComponent c)
Returns preferred size for the combo box.
protected voidinstallComponents()
Installs the components for this JComboBox.
protected voidinstallDefaults()
Installs the defaults that are defined in the {@link BasicLookAndFeel} for this {@link JComboBox}.
protected voidinstallKeyboardActions()
Installs the keyboard actions for the {@link JComboBox} as specified by the look and feel.
protected voidinstallListeners()
Creates and installs the listeners for this UI.
voidinstallUI(JComponent c)
Installs the UI for the given {@link JComponent}.
booleanisFocusTraversable(JComboBox c)
JComboBox is focus traversable if it is editable and not otherwise.
protected booleanisNavigationKey(int keyCode)
Returns true if the specified key is a navigation key and false otherwise
booleanisPopupVisible(JComboBox c)
Returns true if the popup is visible, and false otherwise.
voidpaint(Graphics g, JComponent c)
Paints given menu item using specified graphics context
voidpaintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
Paints currently selected value in the main part of the combo box (part without popup).
voidpaintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
Paints the background of part of the combo box, where currently selected value is displayed.
protected RectanglerectangleForCurrentValue()
Returns the bounds in which comboBox's selected item will be displayed.
voidremoveEditor()
Removes the current editor from the combo box.
protected voidselectNextPossibleValue()
Selects next possible item relative to the current selection to be next selected item in the combo box.
protected voidselectPreviousPossibleValue()
Selects previous item relative to current selection to be next selected item.
voidsetPopupVisible(JComboBox c, boolean v)
Displays/hides the {@link JComboBox}'s list of items on the screen.
protected voidtoggleOpenClose()
Displays combo box popup if the popup is not currently shown on the screen and hides it if it is currently shown
voidunconfigureArrowButton()
Unconfigures the arrow button.
protected voidunconfigureEditor()
Unconfigures the editor for this combo box.
protected voiduninstallComponents()
Uninstalls components from this {@link JComboBox}.
protected voiduninstallDefaults()
Uninstalls the defaults and sets any objects created during install to null.
protected voiduninstallKeyboardActions()
Uninstalls the keyboard actions for the {@link JComboBox} there were installed by in {@link #installListeners}.
protected voiduninstallListeners()
Detaches all the listeners we attached in {@link #installListeners}.
voiduninstallUI(JComponent c)
Uninstalls the UI for the given {@link JComponent}.

Field Detail

arrowButton

protected JButton arrowButton
The arrow button that is displayed in the right side of JComboBox. This button is used to hide and show combo box's list of items.

cachedMinimumSize

protected Dimension cachedMinimumSize
The current minimum size if isMinimumSizeDirty is false. Setup by getMinimumSize() and invalidated by the various listeners.

comboBox

protected JComboBox comboBox
The combo box represented by this UI delegate.

currentValuePane

protected CellRendererPane currentValuePane
Used to render the combo box values.

editor

protected Component editor
The component that is responsible for displaying/editing the selected item of the combo box.

See Also: getEditorComponent

focusListener

protected FocusListener focusListener
A listener listening to focus events occurring in the {@link JComboBox}.

hasFocus

protected boolean hasFocus
A flag indicating whether JComboBox currently has the focus.

isMinimumSizeDirty

protected boolean isMinimumSizeDirty
Indicates whether or not the cachedMinimumSize field is valid or not.

itemListener

protected ItemListener itemListener
A listener listening to item events fired by the {@link JComboBox}.

keyListener

protected KeyListener keyListener
A listener listening to key events that occur while {@link JComboBox} has the focus.

listBox

protected JList listBox
List used when rendering selected item of the combo box. The selection and foreground colors for combo box renderer are configured from this list.

listDataListener

protected ListDataListener listDataListener
ListDataListener listening to JComboBox model

popup

protected ComboPopup popup
Popup list containing the combo box's menu items.

popupKeyListener

protected KeyListener popupKeyListener

popupMouseListener

protected MouseListener popupMouseListener

popupMouseMotionListener

protected MouseMotionListener popupMouseMotionListener

propertyChangeListener

protected PropertyChangeListener propertyChangeListener
Listener listening to changes in the bound properties of JComboBox

Constructor Detail

BasicComboBoxUI

public BasicComboBoxUI()
Creates a new BasicComboBoxUI object.

Method Detail

addEditor

public void addEditor()
Adds the current editor to the combo box.

configureArrowButton

public void configureArrowButton()
Configures the arrow button.

See Also: configureArrowButton

configureEditor

protected void configureEditor()
Configures the editor for this combo box.

createArrowButton

protected JButton createArrowButton()
Creates an arrow button for this {@link JComboBox}. The arrow button is displayed at the right end of the combo box and is used to display/hide the drop down list of items.

Returns: A new button.

createEditor

protected ComboBoxEditor createEditor()
Creates the component that will be responsible for displaying/editing the selected item in the combo box. This editor is used only when combo box is editable.

Returns: A new component that will be responsible for displaying/editing the selected item in the combo box.

createFocusListener

protected FocusListener createFocusListener()
Creates the {@link FocusListener} that will listen to changes in this JComboBox's focus.

Returns: the FocusListener.

createItemListener

protected ItemListener createItemListener()
Creates an {@link ItemListener} that will listen to the changes in the JComboBox's selection.

Returns: The ItemListener

createKeyListener

protected KeyListener createKeyListener()
Creates a {@link KeyListener} to listen to key events.

Returns: KeyListener that listens to key events.

createLayoutManager

protected LayoutManager createLayoutManager()
Creates and returns a layout manager for the combo box. Subclasses can override this method to provide a different layout.

Returns: a layout manager for the combo box.

createListDataListener

protected ListDataListener createListDataListener()
Creates a {@link ListDataListener} to listen to the combo box's data model.

Returns: The new listener.

createPopup

protected ComboPopup createPopup()
Creates the popup that will contain list of combo box's items.

Returns: popup containing list of combo box's items

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates a {@link PropertyChangeListener} to listen to the changes in the JComboBox's bound properties.

Returns: The PropertyChangeListener

createRenderer

protected ListCellRenderer createRenderer()
Creates a component that will be responsible for rendering the selected component in the combo box.

Returns: A renderer for the combo box.

createUI

public static ComponentUI createUI(JComponent c)
A factory method to create a UI delegate for the given {@link JComponent}, which should be a {@link JComboBox}.

Parameters: c The {@link JComponent} a UI is being created for.

Returns: A UI delegate for the {@link JComponent}.

getAccessibleChild

public Accessible getAccessibleChild(JComponent c, int i)
Returns the accessible child with the specified index.

Parameters: c the component, this is ignored i the index of the accessible child to return

getAccessibleChildrenCount

public int getAccessibleChildrenCount(JComponent c)
Returns the number of accessible children of the combobox.

Parameters: c the component (combobox) to check, ignored

Returns: the number of accessible children of the combobox

getDefaultSize

protected Dimension getDefaultSize()
Returns the default size for the display area of a combo box that does not contain any elements. This method returns the width and height of a single space in the current font, plus a margin of 1 pixel.

Returns: The default display size.

See Also: getDisplaySize

getDisplaySize

protected Dimension getDisplaySize()
Returns the size of the display area for the combo box. This size will be the size of the combo box, not including the arrowButton.

Returns: The size of the display area for the combo box.

getInsets

protected Insets getInsets()
Returns the insets of the current border.

Returns: Insets representing space between combo box and its border

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Returns the maximum size for this {@link JComboBox} for this look and feel.

Parameters: c The {@link JComponent} to find the maximum size for

Returns: The maximum size (Dimension(32767, 32767)).

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Returns the minimum size for this {@link JComboBox} for this look and feel. Also makes sure cachedMinimimSize is setup correctly.

Parameters: c The {@link JComponent} to find the minimum size for.

Returns: The dimensions of the minimum size.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Returns preferred size for the combo box.

Parameters: c comboBox for which to get preferred size

Returns: The preferred size for the given combo box

installComponents

protected void installComponents()
Installs the components for this JComboBox. ArrowButton, main part of combo box (upper part) and popup list of items are created and configured here.

installDefaults

protected void installDefaults()
Installs the defaults that are defined in the {@link BasicLookAndFeel} for this {@link JComboBox}.

See Also: uninstallDefaults

installKeyboardActions

protected void installKeyboardActions()
Installs the keyboard actions for the {@link JComboBox} as specified by the look and feel.

installListeners

protected void installListeners()
Creates and installs the listeners for this UI.

See Also: uninstallListeners

installUI

public void installUI(JComponent c)
Installs the UI for the given {@link JComponent}.

Parameters: c the JComponent to install a UI for.

See Also: uninstallUI

isFocusTraversable

public boolean isFocusTraversable(JComboBox c)
JComboBox is focus traversable if it is editable and not otherwise.

Parameters: c combo box for which to check whether it is focus traversable

Returns: true if focus tranversable and false otherwise

isNavigationKey

protected boolean isNavigationKey(int keyCode)
Returns true if the specified key is a navigation key and false otherwise

Parameters: keyCode a key for which to check whether it is navigation key or not.

Returns: true if the specified key is a navigation key and false otherwis

isPopupVisible

public boolean isPopupVisible(JComboBox c)
Returns true if the popup is visible, and false otherwise.

Parameters: c The JComboBox to check

Returns: true if popup part of the JComboBox is visible and false otherwise.

paint

public void paint(Graphics g, JComponent c)
Paints given menu item using specified graphics context

Parameters: g The graphics context used to paint this combo box c comboBox which needs to be painted.

paintCurrentValue

public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
Paints currently selected value in the main part of the combo box (part without popup).

Parameters: g graphics context bounds Rectangle representing the size of the area in which selected item should be drawn hasFocus true if combo box has focus and false otherwise

paintCurrentValueBackground

public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
Paints the background of part of the combo box, where currently selected value is displayed. If the combo box has focus this method should also paint focus rectangle around the combo box.

Parameters: g graphics context bounds Rectangle representing the size of the largest item in the comboBox hasFocus true if combo box has fox and false otherwise

rectangleForCurrentValue

protected Rectangle rectangleForCurrentValue()
Returns the bounds in which comboBox's selected item will be displayed.

Returns: rectangle bounds in which comboBox's selected Item will be displayed

removeEditor

public void removeEditor()
Removes the current editor from the combo box.

selectNextPossibleValue

protected void selectNextPossibleValue()
Selects next possible item relative to the current selection to be next selected item in the combo box.

selectPreviousPossibleValue

protected void selectPreviousPossibleValue()
Selects previous item relative to current selection to be next selected item.

setPopupVisible

public void setPopupVisible(JComboBox c, boolean v)
Displays/hides the {@link JComboBox}'s list of items on the screen.

Parameters: c The combo box, for which list of items should be displayed/hidden v true if show popup part of the jcomboBox and false to hide.

toggleOpenClose

protected void toggleOpenClose()
Displays combo box popup if the popup is not currently shown on the screen and hides it if it is currently shown

unconfigureArrowButton

public void unconfigureArrowButton()
Unconfigures the arrow button.

See Also:

UNKNOWN: The specification says this method is implementation specific and should not be used or overridden.

unconfigureEditor

protected void unconfigureEditor()
Unconfigures the editor for this combo box.

uninstallComponents

protected void uninstallComponents()
Uninstalls components from this {@link JComboBox}.

See Also: installComponents

uninstallDefaults

protected void uninstallDefaults()
Uninstalls the defaults and sets any objects created during install to null.

See Also: installDefaults

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls the keyboard actions for the {@link JComboBox} there were installed by in {@link #installListeners}.

uninstallListeners

protected void uninstallListeners()
Detaches all the listeners we attached in {@link #installListeners}.

See Also: installListeners

uninstallUI

public void uninstallUI(JComponent c)
Uninstalls the UI for the given {@link JComponent}.

Parameters: c The JComponent that is having this UI removed.

See Also: installUI