java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JComboBox<E>
- Type Parameters:
E
- the type of the elements of this combo box
- All Implemented Interfaces:
ActionListener
,ImageObserver
,ItemSelectable
,MenuContainer
,Serializable
,EventListener
,Accessible
,ListDataListener
@JavaBean(defaultProperty="UI",
description="A combination of a text field and a drop-down list.")
public class JComboBox<E>
extends JComponent
implements ItemSelectable, ListDataListener, ActionListener, Accessible
A component that combines a button or editable field and a drop-down list.
The user can select a value from the drop-down list, which appears at the
user's request. If you make the combo box editable, then the combo box
includes an editable field into which the user can type a value.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans
package.
Please see XMLEncoder
.
See How to Use Combo Boxes in The Java Tutorial for further information.
- Since:
- 1.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
This class implements accessibility support for theJComboBox
class.static interface
The interface that defines aKeySelectionManager
.Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
This protected field is implementation specific.protected ComboBoxModel<E>
This protected field is implementation specific.protected ComboBoxEditor
This protected field is implementation specific.protected boolean
This protected field is implementation specific.protected JComboBox.KeySelectionManager
This protected field is implementation specific.protected boolean
This protected field is implementation specific.protected int
This protected field is implementation specific.protected ListCellRenderer<? super E>
This protected field is implementation specific.protected Object
This protected field is implementation specific.Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionCreates aJComboBox
with a default data model.Creates aJComboBox
that contains the elements in the specified array.Creates aJComboBox
that contains the elements in the specified Vector.JComboBox
(ComboBoxModel<E> aModel) Creates aJComboBox
that takes its items from an existingComboBoxModel
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method is public as an implementation side effect.protected void
actionPropertyChanged
(Action action, String propertyName) Updates the combobox's state in response to property changes in associated action.void
Adds anActionListener
.void
Adds an item to the item list.void
addItemListener
(ItemListener aListener) Adds anItemListener
.void
Adds aPopupMenu
listener which will listen to notification messages from the popup portion of the combo box.void
configureEditor
(ComboBoxEditor anEditor, Object anItem) Initializes the editor with the specified item.protected void
Sets the properties on this combobox to match those in the specifiedAction
.void
This method is public as an implementation side effect.protected PropertyChangeListener
Creates and returns aPropertyChangeListener
that is responsible for listening for changes from the specifiedAction
and updating the appropriate properties.protected JComboBox.KeySelectionManager
Returns an instance of the default key-selection manager.protected void
Notifies all listeners that have registered interest for notification on this event type.protected void
Notifies all listeners that have registered interest for notification on this event type.void
NotifiesPopupMenuListener
s that the popup portion of the combo box has been canceled.void
NotifiesPopupMenuListener
s that the popup portion of the combo box has become invisible.void
NotifiesPopupMenuListener
s that the popup portion of the combo box will become visible.Gets the AccessibleContext associated with this JComboBox.Returns the currently setAction
for thisActionEvent
source, ornull
if noAction
is set.Returns the action command that is included in the event sent to action listeners.Returns an array of all theActionListener
s added to this JComboBox with addActionListener().Returns the editor used to paint and edit the selected item in theJComboBox
field.getItemAt
(int index) Returns the list item at the specified index.int
Returns the number of items in the list.Returns an array of all theItemListener
s added to this JComboBox with addItemListener().Returns the list's key-selection manager.int
Returns the maximum number of items the combo box can display without a scrollbargetModel()
Returns the data model currently used by theJComboBox
.Returns an array of all thePopupMenuListener
s added to this JComboBox with addPopupMenuListener().Returns the "prototypical display" value - an Object used for the calculation of the display height and width.ListCellRenderer<? super E>
Returns the renderer used to display the selected item in theJComboBox
field.int
Returns the first item in the list that matches the given item.Returns the current selected item.Object[]
Returns an array containing the selected item.getUI()
Returns the L&F object that renders this component.Returns the name of the L&F class that renders this component.void
Causes the combo box to close its popup window.void
insertItemAt
(E item, int index) Inserts an item into the item list at a given index.protected void
Registers ancestor listener so that it will receiveAncestorEvents
when it or any of its ancestors move or are made visible or invisible.void
This method is public as an implementation side effect.void
This method is public as an implementation side effect.boolean
Returns true if theJComboBox
is editable.boolean
Gets the value of thelightWeightPopupEnabled
property.boolean
Determines the visibility of the popup.protected String
Returns a string representation of thisJComboBox
.void
HandlesKeyEvent
s, looking for the Tab key.void
Removes anActionListener
.void
Removes all items from the item list.void
removeItem
(Object anObject) Removes an item from the item list.void
removeItemAt
(int anIndex) Removes the item atanIndex
This method works only if theJComboBox
uses a mutable data model.void
removeItemListener
(ItemListener aListener) Removes anItemListener
.void
Removes aPopupMenuListener
.protected void
This protected method is implementation specific.boolean
selectWithKeyChar
(char keyChar) Selects the list item that corresponds to the specified keyboard character and returns true, if there is an item corresponding to that character.void
Sets theAction
for theActionEvent
source.void
setActionCommand
(String aCommand) Sets the action command that should be included in the event sent to action listeners.void
setEditable
(boolean aFlag) Determines whether theJComboBox
field is editable.void
setEditor
(ComboBoxEditor anEditor) Sets the editor used to paint and edit the selected item in theJComboBox
field.void
setEnabled
(boolean b) Enables the combo box so that items can be selected.void
Sets the object that translates a keyboard character into a list selection.void
setLightWeightPopupEnabled
(boolean aFlag) Sets thelightWeightPopupEnabled
property, which provides a hint as to whether or not a lightweightComponent
should be used to contain theJComboBox
, versus a heavyweightComponent
such as aPanel
or aWindow
.void
setMaximumRowCount
(int count) Sets the maximum number of rows theJComboBox
displays.void
setModel
(ComboBoxModel<E> aModel) Sets the data model that theJComboBox
uses to obtain the list of items.void
setPopupVisible
(boolean v) Sets the visibility of the popup.void
setPrototypeDisplayValue
(E prototypeDisplayValue) Sets the prototype display value used to calculate the size of the display for the UI portion.void
setRenderer
(ListCellRenderer<? super E> aRenderer) Sets the renderer that paints the list items and the item selected from the list in the JComboBox field.void
setSelectedIndex
(int anIndex) Selects the item at indexanIndex
.void
setSelectedItem
(Object anObject) Sets the selected item in the combo box display area to the object in the argument.void
setUI
(ComboBoxUI ui) Sets the L&F object that renders this component.void
Causes the combo box to display its popup window.void
updateUI()
Resets the UI property to a value from the current look and feel.Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale,