javax.swing.plaf.basic
Class BasicComboBoxUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.ComboBoxUI
          extended by javax.swing.plaf.basic.BasicComboBoxUI
Direct Known Subclasses:
MetalComboBoxUI

public class BasicComboBoxUI
extends ComboBoxUI

A UI delegate for the JComboBox component.


Nested Class Summary
 class BasicComboBoxUI.ComboBoxLayoutManager
          A LayoutManager used to position the sub-components of the JComboBox.
 class BasicComboBoxUI.FocusHandler
          Handles focus changes occuring in the combo box.
 class BasicComboBoxUI.ItemHandler
          Handles ItemEvents fired by the JComboBox when its selected item changes.
 class BasicComboBoxUI.KeyHandler
          KeyHandler handles key events occuring while JComboBox has focus.
 class BasicComboBoxUI.ListDataHandler
          Handles the changes occurring in the JComboBox's data model.
 class BasicComboBoxUI.PropertyChangeHandler
          Handles PropertyChangeEvents fired by the JComboBox.
 
Field Summary
protected  JButton arrowButton
          The arrow button that is displayed in the right side of JComboBox.
protected  Dimension cachedMinimumSize
          The current minimum size if isMinimumSizeDirty is false.
protected  JComboBox comboBox
          The combo box represented by this UI delegate.
protected  CellRendererPane currentValuePane
          Used to render the combo box values.
protected  Component editor
          The component that is responsible for displaying/editing the selected item of the combo box.
protected  FocusListener focusListener
          A listener listening to focus events occurring in the JComboBox.
protected  boolean hasFocus
          A flag indicating whether JComboBox currently has the focus.
protected  boolean isMinimumSizeDirty
          Indicates whether or not the cachedMinimumSize field is valid or not.
protected  ItemListener itemListener
          A listener listening to item events fired by the JComboBox.
protected  KeyListener keyListener
          A listener listening to key events that occur while JComboBox has the focus.
protected  JList listBox
          List used when rendering selected item of the combo box.
protected  ListDataListener listDataListener
          ListDataListener listening to JComboBox model
protected  ComboPopup popup
          Popup list containing the combo box's menu items.
protected  KeyListener popupKeyListener
           
protected  MouseListener popupMouseListener
           
protected  MouseMotionListener popupMouseMotionListener
           
protected  PropertyChangeListener propertyChangeListener
          Listener listening to changes in the bound properties of JComboBox
 
Constructor Summary
BasicComboBoxUI()
          Creates a new BasicComboBoxUI object.
 
Method Summary
 void addEditor()
          Adds the current editor to the combo box.
 void configureArrowButton()
          Configures the arrow button.
protected  void configureEditor()
          Configures the editor for this combo box.
protected  JButton createArrowButton()
          Creates an arrow button for this JComboBox.
protected  ComboBoxEditor createEditor()
          Creates the component that will be responsible for displaying/editing the selected item in the combo box.
protected  FocusListener createFocusListener()
          Creates the FocusListener that will listen to changes in this JComboBox's focus.
protected  ItemListener createItemListener()
          Creates an ItemListener that will listen to the changes in the JComboBox's selection.
protected  KeyListener createKeyListener()
          Creates a KeyListener to listen to key events.
protected  LayoutManager createLayoutManager()
          Creates and returns a layout manager for the combo box.
protected  ListDataListener createListDataListener()
          Creates a ListDataListener to listen to the combo box's data model.
protected  ComboPopup createPopup()
          Creates the popup that will contain list of combo box's items.
protected  PropertyChangeListener createPropertyChangeListener()
          Creates a PropertyChangeListener to listen to the changes in the JComboBox's bound properties.
protected  ListCellRenderer createRenderer()
          Creates a component that will be responsible for rendering the selected component in the combo box.
static ComponentUI createUI(JComponent c)
          A factory method to create a UI delegate for the given JComponent, which should be a JComboBox.
 Accessible getAccessibleChild(JComponent c, int i)
          Returns the accessible child with the specified index.
 int getAccessibleChildrenCount(JComponent c)
          Returns the number of accessible children of the combobox.
protected  Dimension getDefaultSize()
          Returns the default size for the display area of a combo box that does not contain any elements.
protected  Dimension getDisplaySize()
          Returns the size of the display area for the combo box.
protected  Insets getInsets()
          Returns the insets of the current border.
 Dimension getMaximumSize(JComponent c)
          Returns the maximum size for this JComboBox for this look and feel.
 Dimension getMinimumSize(JComponent c)
          Returns the minimum size for this JComboBox for this look and feel.
 Dimension getPreferredSize(JComponent c)
          Returns preferred size for the combo box.
protected  void installComponents()
          Installs the components for this JComboBox.
protected  void installDefaults()
          Installs the defaults that are defined in the BasicLookAndFeel for this JComboBox.
protected  void installKeyboardActions()
          Installs the keyboard actions for the JComboBox as specified by the look and feel.
protected  void installListeners()
          Creates and installs the listeners for this UI.
 void installUI(JComponent c)
          Installs the UI for the given JComponent.
 boolean isFocusTraversable(JComboBox c)
          JComboBox is focus traversable if it is editable and not otherwise.
protected  boolean isNavigationKey(int keyCode)
          Returns true if the specified key is a navigation key and false otherwise
 boolean isPopupVisible(JComboBox c)
          Returns true if the popup is visible, and false otherwise.
 void paint(Graphics g, JComponent c)
          Paints given menu item using specified graphics context
 void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
          Paints currently selected value in the main part of the combo box (part without popup).
 void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
          Paints the background of part of the combo box, where currently selected value is displayed.
protected  Rectangle rectangleForCurrentValue()
          Returns the bounds in which comboBox's selected item will be displayed.
 void removeEditor()
          Removes the current editor from the combo box.
protected  void selectNextPossibleValue()
          Selects next possible item relative to the current selection to be next selected item in the combo box.
protected  void selectPreviousPossibleValue()
          Selects previous item relative to current selection to be next selected item.
 void setPopupVisible(JComboBox c, boolean v)
          Displays/hides the JComboBox's list of items on the screen.
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
 void unconfigureArrowButton()
          Unconfigures the arrow button.
protected  void unconfigureEditor()
          Unconfigures the editor for this combo box.
protected  void uninstallComponents()
          Uninstalls components from this JComboBox.
protected  void uninstallDefaults()
          Uninstalls the defaults and sets any objects created during install to null.
protected  void uninstallKeyboardActions()
          Uninstalls the keyboard actions for the JComboBox there were installed by in installListeners().
protected  void uninstallListeners()
          Detaches all the listeners we attached in installListeners().
 void uninstallUI(JComponent c)
          Uninstalls the UI for the given JComponent.
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.


comboBox

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


editor

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

See Also:
BasicComboBoxEditor.getEditorComponent()

focusListener

protected FocusListener focusListener
A listener listening to focus events occurring in the JComboBox.


hasFocus

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


itemListener

protected ItemListener itemListener
A listener listening to item events fired by the JComboBox.


keyListener

protected KeyListener keyListener
A listener listening to key events that occur while 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


currentValuePane

protected CellRendererPane currentValuePane
Used to render the combo box values.


cachedMinimumSize

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


isMinimumSizeDirty

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

Constructor Detail

BasicComboBoxUI

public BasicComboBoxUI()
Creates a new BasicComboBoxUI object.

Method Detail

createUI

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

Parameters:
c - The JComponent a UI is being created for.
Returns:
A UI delegate for the JComponent.

installUI

public void installUI(JComponent c)
Installs the UI for the given JComponent.

Overrides:
installUI in class ComponentUI
Parameters:
c - the JComponent to install a UI for.
See Also:
uninstallUI(JComponent)

uninstallUI

public void uninstallUI(JComponent c)
Uninstalls the UI for the given JComponent.

Overrides:
uninstallUI in class ComponentUI
Parameters:
c - The JComponent that is having this UI removed.
See Also:
installUI(JComponent)

installDefaults

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

See Also:
uninstallDefaults()

installListeners

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

See Also:
uninstallListeners()

uninstallDefaults

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

See Also:
installDefaults()

uninstallListeners

protected void uninstallListeners()
Detaches all the listeners we attached in installListeners().

See Also:
installListeners()

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

createKeyListener

protected KeyListener createKeyListener()
Creates a KeyListener to listen to key events.

Returns:
KeyListener that listens to key events.

createFocusListener

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

Returns:
the FocusListener.

createListDataListener

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

Returns:
The new listener.

createItemListener

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

Returns:
The ItemListener

createPropertyChangeListener

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

Returns:
The PropertyChangeListener

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.

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.

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.

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.


uninstallComponents

protected void uninstallComponents()
Uninstalls components from this JComboBox.

See Also:
installComponents()

addEditor

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


removeEditor

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


configureEditor

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


unconfigureEditor

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


configureArrowButton

public void configureArrowButton()
Configures the arrow button.

See Also:
configureArrowButton()

unconfigureArrowButton

public void unconfigureArrowButton()
Unconfigures the arrow button.

See Also:
configureArrowButton()

createArrowButton

protected JButton createArrowButton()
Creates an arrow button for this 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.

isPopupVisible

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

Specified by:
isPopupVisible in class ComboBoxUI
Parameters:
c - The JComboBox to check
Returns:
true if popup part of the JComboBox is visible and false otherwise.

setPopupVisible

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

Specified by:
setPopupVisible in class ComboBoxUI
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.

isFocusTraversable

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

Specified by:
isFocusTraversable in class ComboBoxUI
Parameters:
c - combo box for which to check whether it is focus traversable
Returns:
true if focus tranversable and false otherwise

paint

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

Overrides:
paint in class ComponentUI
Parameters:
g - The graphics context used to paint this combo box
c - comboBox which needs to be painted.

getPreferredSize

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

Overrides:
getPreferredSize in class ComponentUI
Parameters:
c - comboBox for which to get preferred size
Returns:
The preferred size for the given combo box

getMinimumSize

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

Overrides:
getMinimumSize in class ComponentUI
Parameters:
c - The JComponent to find the minimum size for.
Returns:
The dimensions of the minimum size.

getMaximumSize

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

Overrides:
getMaximumSize in class ComponentUI
Parameters:
c - The JComponent to find the maximum size for
Returns:
The maximum size (Dimension(32767, 32767)).

getAccessibleChildrenCount

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

Overrides:
getAccessibleChildrenCount in class ComponentUI
Parameters:
c - the component (combobox) to check, ignored
Returns:
the number of accessible children of the combobox

getAccessibleChild

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

Overrides:
getAccessibleChild in class ComponentUI
Parameters:
c - the component, this is ignored
i - the index of the accessible child to return

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

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.


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


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

getInsets

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

Returns:
Insets representing space between combo box and its border

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

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.

installKeyboardActions

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


uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls the keyboard actions for the JComboBox there were installed by in installListeners().