javax.swing.plaf.basic

Class BasicComboBoxUI

Known Direct Subclasses:
MetalComboBoxUI

public class BasicComboBoxUI
extends ComboBoxUI

UI Delegate for JComboBox

Nested Class Summary

class
BasicComboBoxUI.ComboBoxLayoutManager
This class is Layout Manager for this combo box.
class
BasicComboBoxUI.FocusHandler
This class handles focus changes occuring in the combo box.
class
BasicComboBoxUI.ItemHandler
This class handles ItemEvent fired by the JComboBox when its selected item changes.
class
BasicComboBoxUI.KeyHandler
KeyHandler handles key events occuring while JComboBox has focus.
class
BasicComboBoxUI.ListDataHandler
This class handles to the changes occuring in the JComboBox's data model
class
BasicComboBoxUI.PropertyChangeHandler
This class handles PropertyChangeEvents fired by JComboBox.

Field Summary

protected JButton
arrowButton
This arrow button that is displayed in the rigth side of JComboBox.
protected Dimension
cachedMinimumSize
protected JComboBox
comboBox
The combo box for which this UI delegate is for
protected CellRendererPane
currentValuePane
protected Component
editor
Component that is responsible for displaying/editting selected item of the combo box.
protected FocusListener
focusListener
Listener listening to focus events occuring in the JComboBox
protected boolean
hasFocus
tells whether JComboBox currently has focus
protected boolean
isMinimumSizeDirty
protected ItemListener
itemListener
Listener listening to item events fired by the JComboBox
protected KeyListener
keyListener
KeyListener listening to key events that occur while JComboBox has 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 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()
This method adds editor to the combo box
void
configureArrowButton()
This method adds listeners to the arrow button part of the combo box.
protected void
configureEditor()
This method configures editor for this combo box.
protected JButton
createArrowButton()
This method create arrow button for this JComboBox.
protected ComboBoxEditor
createEditor()
Creates component that will be responsible for displaying/editting selected item in the combo box.
protected FocusListener
createFocusListener()
This method create FocusListener that will listen to changes in this JComboBox's focus.
protected ItemListener
createItemListener()
This method creates ItemListener that will listen to to the changes in the JComboBox's selection.
protected KeyListener
createKeyListener()
Creates KeyListener to listen to key events.
protected LayoutManager
createLayoutManager()
This method returns layout manager for the combo box.
protected ListDataListener
createListDataListener()
This method create ListDataListener to listen to ComboBox's data model
protected ComboPopup
createPopup()
This method creates popup that will contain list of combo box's items
protected PropertyChangeListener
createPropertyChangeListener()
This method creates PropertyChangeListener to listen to the changes in the JComboBox's bound properties.
protected ListCellRenderer
createRenderer()
This method creates component that will be responsible for rendering the selected component in the combo box.
static ComponentUI
createUI(JComponent c)
Factory method to create a BasicComboBoxUI for the given JComponent, which should be a JComboBox.
Accessible
getAccessibleChild(JComponent c, int i)
Returns the specified accessible child of the component.
int
getAccessibleChildrenCount(JComponent c)
Counts the number of accessible children in the component.
protected Dimension
getDefaultSize()
Returns default size for the combo box that doesn't contain any elements in it
protected Insets
getInsets()
This method returns insets of the current border.
protected Dimension
getLargestItemSize()
Returns size of the largest item in the combo box.
Dimension
getMaximumSize(JComponent c)
This method returns the maximum size for this JComboBox for this look and feel.
Dimension
getMinimumSize(JComponent c)
This method returns the minimum size for this JComboBox for this look and feel.
Dimension
getPreferredSize(JComponent c)
Returns preferred size for the given menu item.
protected void
installComponents()
This method installs components for this JComboBox.
protected void
installDefaults()
This method installs the defaults that are defined in the Basic look and feel for this JComboBox.
protected void
installKeyboardActions()
This method installs the keyboard actions for the JComboBox as specified by the look and feel.
protected void
installListeners()
This method creates and installs the listeners for this UI.
void
installUI(JComponent c)
This method 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)
This method checks if popup part of the combo box is visible on the screen
void
paint(Graphics g, JComponent c)
Paints given menu item using specified graphics context
void
paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
This method paints currently selected value in the main part of the combo box (part without popup).
void
paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
This method paints background of part of the combo box, where currently selected value is displayed.
protected Rectangle
rectangleForCurrentValue()
This method returns bounds in which comboBox's selected Item will be displayed
void
removeEditor()
This method removes editor from the combo box
protected void
selectNextPossibleValue()
This method selects next possible item relative to the current selection to be next selected item in the combo box.
protected void
selectPreviousPossibleValue()
This method selects previous item relative to current selection to be next selected item.
void
setPopupVisible(JComboBox c, boolean v)
Displays/Hides JComboBox's list of items on the screen.
protected void
toggleOpenClose()
This method displays combo box popup if the popup is not currently shown on the screen and hides it if it is currently shown
void
unconfigureArrowButton()
This method removes listeners from the arrow button part of the combo box.
protected void
unconfigureEditor()
This method removes all the listeners for the editor.
protected void
uninstallComponents()
This method uninstalls components from this JComboBox
protected void
uninstallDefaults()
This method uninstalls the defaults and sets any objects created during install to null
protected void
uninstallKeyboardActions()
This method 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)
This method uninstalls the UI.

Methods inherited from class javax.swing.plaf.ComboBoxUI

isFocusTraversable, isPopupVisible, setPopupVisible

Methods inherited from class javax.swing.plaf.ComponentUI

contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

arrowButton

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


cachedMinimumSize

protected Dimension cachedMinimumSize


comboBox

protected JComboBox comboBox
The combo box for which this UI delegate is for


currentValuePane

protected CellRendererPane currentValuePane


editor

protected Component editor
Component that is responsible for displaying/editting selected item of the combo box. By default JTextField is used as an editor for the JComboBox


focusListener

protected FocusListener focusListener
Listener listening to focus events occuring in the JComboBox


hasFocus

protected boolean hasFocus
tells whether JComboBox currently has focus


isMinimumSizeDirty

protected boolean isMinimumSizeDirty


itemListener

protected ItemListener itemListener
Listener listening to item events fired by the JComboBox


keyListener

protected KeyListener keyListener
KeyListener listening to key events that occur while JComboBox has 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 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 Details

BasicComboBoxUI

public BasicComboBoxUI()
Creates a new BasicComboBoxUI object.

Method Details

addEditor

public void addEditor()
This method adds editor to the combo box


configureArrowButton

public void configureArrowButton()
This method adds listeners to the arrow button part of the combo box.


configureEditor

protected void configureEditor()
This method configures editor for this combo box.


createArrowButton

protected JButton createArrowButton()
This method create arrow button for this JComboBox. Arrow button is responsible for displaying / hiding drop down list of items when it is clicked.

Returns:
JButton arrow button for this JComboBox.


createEditor

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

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


createFocusListener

protected FocusListener createFocusListener()
This method create FocusListener that will listen to changes in this JComboBox's focus.

Returns:
theFocusListener


createItemListener

protected ItemListener createItemListener()
This method creates ItemListener that will listen to to the changes in the JComboBox's selection.

Returns:
the ItemListener


createKeyListener

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

Returns:
KeyListener that listens to key events.


createLayoutManager

protected LayoutManager createLayoutManager()
This method returns layout manager for the combo box.

Returns:
layout manager for the combo box


createListDataListener

protected ListDataListener createListDataListener()
This method create ListDataListener to listen to ComboBox's data model

Returns:
ListDataListener


createPopup

protected ComboPopup createPopup()
This method creates popup that will contain list of combo box's items

Returns:
popup containing list of combo box's items


createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
This method creates PropertyChangeListener to listen to the changes in the JComboBox's bound properties.

Returns:
the PropertyChangeListener


createRenderer

protected ListCellRenderer createRenderer()
This method creates component that will be responsible for rendering the selected component in the combo box.

Returns:
render for the combo box


createUI

public static ComponentUI createUI(JComponent c)
Factory method to create a BasicComboBoxUI for the given JComponent, which should be a JComboBox.
Overrides:
createUI in interface ComponentUI

Parameters:
c - The JComponent a UI is being created for.

Returns:
A BasicComboBoxUI for the JComponent.


getAccessibleChild

public Accessible getAccessibleChild(JComponent c,
                                     int i)
Returns the specified accessible child of the component. The default implementation delegates the inquiry to the AccessibleContext of c.
Overrides:
getAccessibleChild in interface ComponentUI

Parameters:
c - the component whose i-th accessible child is requested.
i - the index of the accessible child, starting at zero.


getAccessibleChildrenCount

public int getAccessibleChildrenCount(JComponent c)
Counts the number of accessible children in the component. The default implementation delegates the inquiry to the AccessibleContext of c.
Overrides:
getAccessibleChildrenCount in interface ComponentUI

Parameters:
c - the component whose accessible children are to be counted.


getDefaultSize

protected Dimension getDefaultSize()
Returns default size for the combo box that doesn't contain any elements in it

Returns:
Default size of the combo box with no elements in it.


getInsets

protected Insets getInsets()
This method returns insets of the current border.

Returns:
Insets representing space between combo box and its border


getLargestItemSize

protected Dimension getLargestItemSize()
Returns size of the largest item in the combo box. This size will be the size of the combo box, not including the arrowButton.

Returns:
dimensions of the largest item in the combo box.


getMaximumSize

public Dimension getMaximumSize(JComponent c)
This method returns the maximum size for this JComboBox for this look and feel.
Overrides:
getMaximumSize in interface ComponentUI

Parameters:
c - The JComponent to find the maximum size for

Returns:
The dimensions of the minimum size.


getMinimumSize

public Dimension getMinimumSize(JComponent c)
This method returns the minimum size for this JComboBox for this look and feel.
Overrides:
getMinimumSize in interface ComponentUI

Parameters:
c - The 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 given menu item.
Overrides:
getPreferredSize in interface ComponentUI

Parameters:
c - comboBox for which to get preferred size

Returns:
$Dimension$ preferred size for the given combo box


installComponents

protected void installComponents()
This method installs 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()
This method installs the defaults that are defined in the Basic look and feel for this JComboBox.


installKeyboardActions

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


installListeners

protected void installListeners()
This method creates and installs the listeners for this UI.


installUI

public void installUI(JComponent c)
This method installs the UI for the given JComponent.
Overrides:
installUI in interface ComponentUI

Parameters:
c - The JComponent to install a UI for.


isFocusTraversable

public boolean isFocusTraversable(JComboBox c)
JComboBox is focus traversable if it is editable and not otherwise.
Overrides:
isFocusTraversable in interface ComboBoxUI

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)
This method checks if popup part of the combo box is visible on the screen
Overrides:
isPopupVisible in interface ComboBoxUI

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
Overrides:
paint in interface ComponentUI

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)
This method 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)
This method paints 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()
This method returns 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()
This method removes editor from the combo box


selectNextPossibleValue

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


selectPreviousPossibleValue

protected void selectPreviousPossibleValue()
This method selects previous item relative to current selection to be next selected item.


setPopupVisible

public void setPopupVisible(JComboBox c,
                            boolean v)
Displays/Hides JComboBox's list of items on the screen.
Overrides:
setPopupVisible in interface 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.


toggleOpenClose

protected void toggleOpenClose()
This method 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()
This method removes listeners from the arrow button part of the combo box.


unconfigureEditor

protected void unconfigureEditor()
This method removes all the listeners for the editor.


uninstallComponents

protected void uninstallComponents()
This method uninstalls components from this JComboBox


uninstallDefaults

protected void uninstallDefaults()
This method uninstalls the defaults and sets any objects created during install to null


uninstallKeyboardActions

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


uninstallListeners

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


uninstallUI

public void uninstallUI(JComponent c)
This method uninstalls the UI.
Overrides:
uninstallUI in interface ComponentUI

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


BasicComboBoxUI.java -- Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.