javax.swing
public class JComboBox extends JComponent implements ItemSelectable, ListDataListener, ActionListener, Accessible
Nested Class Summary | |
---|---|
protected class | JComboBox.AccessibleJComboBox
Accessibility support for JComboBox . |
static interface | JComboBox.KeySelectionManager
Classes implementing this interface are
responsible for matching key characters typed by the user with combo
box's items. |
Field Summary | |
---|---|
protected String | actionCommand
This actionCommand is used in ActionEvent that is fired to JComboBox's
ActionListeneres. |
protected ComboBoxModel | dataModel
Data model used by JComboBox to keep track of its list data and currently
selected element in the list. |
protected ComboBoxEditor | editor
Editor that is responsible for editing an object in a combo box list. |
protected boolean | isEditable
This field indicates if textfield of this JComboBox is editable or not. |
protected JComboBox.KeySelectionManager | keySelectionManager
keySelectionManager |
protected boolean | lightWeightPopupEnabled
This property indicates if heavyweight popup or lightweight popup will be
used to diplay JComboBox's elements. |
protected int | maximumRowCount
Number of rows that will be visible in the JComboBox's popup. |
protected ListCellRenderer | renderer
Renderer renders(paints) every object in the combo box list in its
associated list cell. |
protected Object | selectedItemReminder
This field is reference to the current selection of the combo box. |
Constructor Summary | |
---|---|
JComboBox(ComboBoxModel model)
Constructs JComboBox object with specified data model for it.
| |
JComboBox(Object[] itemArray)
Constructs JComboBox with specified list of items.
| |
JComboBox(Vector<?> itemVector)
Constructs JComboBox object with specified list of items.
| |
JComboBox()
Constructor. |
Method Summary | |
---|---|
void | actionPerformed(ActionEvent e)
This method handles actionEvents fired by the ComboBoxEditor. |
void | addActionListener(ActionListener listener)
This methods adds specified ActionListener to this JComboBox.
|
void | addItem(Object element)
This method adds given element to this JComboBox.
|
void | addItemListener(ItemListener listener)
This method registers given ItemListener with this JComboBox
|
void | addPopupMenuListener(PopupMenuListener listener)
Adds PopupMenuListener to combo box to listen to the events fired by the
combo box's popup menu containing its list of items
|
void | configureEditor(ComboBoxEditor anEditor, Object anItem)
This method initializes specified ComboBoxEditor to display given item.
|
protected void | configurePropertiesFromAction(Action a)
Configure properties of the JComboBox by reading properties of specified
action. |
void | contentsChanged(ListDataEvent event)
The part of implementation of ListDataListener interface. |
protected PropertyChangeListener | createActionPropertyChangeListener(Action action)
Creates PropertyChangeListener to listen for the changes in comboBox's
action properties.
|
protected JComboBox.KeySelectionManager | createDefaultKeySelectionManager()
createDefaultKeySelectionManager
|
protected void | fireActionEvent()
This method fires ActionEvent to this JComboBox's registered
ActionListeners. |
protected void | fireItemStateChanged(ItemEvent e)
This method fires ItemEvent to this JComboBox's registered ItemListeners.
|
void | firePopupMenuCanceled()
Fires a popupMenuCanceled() event to all PopupMenuListeners .
|
void | firePopupMenuWillBecomeInvisible()
Fires a popupMenuWillBecomeInvisible() event to all
PopupMenuListeners .
|
void | firePopupMenuWillBecomeVisible()
Fires a popupMenuWillBecomeVisible() event to all
PopupMenuListeners .
|
AccessibleContext | getAccessibleContext()
Returns the object that provides accessibility features for this
JComboBox component.
|
Action | getAction()
This method returns Action that is invoked when selected item is changed
in the JComboBox.
|
String | getActionCommand()
Returns actionCommand associated with the ActionEvent fired by the
JComboBox to its registered ActionListeners.
|
ActionListener[] | getActionListeners()
This method returns array of ActionListeners that are registered with
this JComboBox.
|
ComboBoxEditor | getEditor()
Returns editor component that is responsible for displaying/editing
selected item in the combo box.
|
Object | getItemAt(int index)
Returns elements located in the combo box at the given index.
|
int | getItemCount()
This method returns number of elements in this JComboBox
|
ItemListener[] | getItemListeners()
This method returns array of ItemListeners that are registered with this
JComboBox.
|
JComboBox.KeySelectionManager | getKeySelectionManager()
getKeySelectionManager
|
int | getMaximumRowCount()
This method returns number of rows visible in the JComboBox's list of
items.
|
ComboBoxModel | getModel()
This method returns data model for this comboBox.
|
PopupMenuListener[] | getPopupMenuListeners()
Returns array of PopupMenuListeners that are registered with combo box. |
Object | getPrototypeDisplayValue()
Returns an object that is used as the display value when calculating the
preferred size for the combo box. |
ListCellRenderer | getRenderer()
This method returns renderer responsible for rendering selected item in
the combo box
|
int | getSelectedIndex()
Returns index of the item that is currently selected in the combo box. |
Object | getSelectedItem()
Returns currently selected item in the combo box.
|
Object[] | getSelectedObjects()
Returns Object array of size 1 containing currently selected element in
the JComboBox.
|
ComboBoxUI | getUI()
This method returns the UI used to display the JComboBox.
|
String | getUIClassID()
This method returns the String identifier for the UI class to the used
with the JComboBox.
|
void | hidePopup()
This method hides popup containing list of combo box's items |
void | insertItemAt(Object element, int index)
Inserts given element at the specified index to this JComboBox.
|
protected void | installAncestorListener() |
void | intervalAdded(ListDataEvent event)
The part of implementation of ListDataListener interface. |
void | intervalRemoved(ListDataEvent event)
The part of implementation of ListDataListener interface. |
boolean | isEditable()
This method returns true JComboBox is editable and false otherwise
|
boolean | isLightWeightPopupEnabled()
This method returns whether popup menu that is used to display list of
combo box's item is lightWeight or not.
|
boolean | isPopupVisible()
Checks if popup is currently visible on the screen.
|
protected String | paramString()
Returns an implementation-dependent string describing the attributes of
this JComboBox .
|
void | processKeyEvent(KeyEvent e)
This method is fired whenever a key is pressed with the combo box
in focus
|
void | removeActionListener(ActionListener listener)
This method removes specified ActionListener from this JComboBox.
|
void | removeAllItems()
This method removes all elements from this JComboBox.
|
void | removeItem(Object element)
This method removes given element from this JComboBox.
|
void | removeItemAt(int index)
This method remove element location in the specified index in the
JComboBox.
|
void | removeItemListener(ItemListener listener)
This method unregisters given ItemListener from this JComboBox
|
void | removePopupMenuListener(PopupMenuListener listener)
Removes PopupMenuListener to combo box to listen to the events fired by
the combo box's popup menu containing its list of items
|
protected void | selectedItemChanged()
This method is invoked whenever selected item changes in the combo box's
data model. |
boolean | selectWithKeyChar(char keyChar)
This method selects item in this combo box that matches specified
specified keyChar and returns true if such item is found. |
void | setAction(Action a)
setAction
|
void | setActionCommand(String aCommand)
This method sets actionCommand to the specified string. |
void | setEditable(boolean editable)
This method sets editability of the combo box. |
void | setEditor(ComboBoxEditor newEditor)
Sets editor for this JComboBox
|
void | setEnabled(boolean enabled)
This method disables or enables JComboBox. |
void | setKeySelectionManager(JComboBox.KeySelectionManager aManager)
setKeySelectionManager
|
void | setLightWeightPopupEnabled(boolean enabled)
This method sets JComboBox's popup to be either lightweight or
heavyweight. |
void | setMaximumRowCount(int rowCount)
Sets number of rows that should be visible in this JComboBox's popup. |
void | setModel(ComboBoxModel newDataModel)
Set the data model for this JComboBox. |
void | setPopupVisible(boolean visible)
This method either displayes or hides the popup containing list of combo
box's items.
|
void | setPrototypeDisplayValue(Object value)
Sets the object that is assumed to be the displayed item when calculating
the preferred size for the combo box. |
void | setRenderer(ListCellRenderer aRenderer)
This method sets cell renderer for this JComboBox that will be used to
paint combo box's items. |
void | setSelectedIndex(int index)
Forces JComboBox to select component located in the given index in the
combo box.
|
void | setSelectedItem(Object item)
Forces combo box to select given item
|
void | setUI(ComboBoxUI ui)
Set the "UI" property of the combo box, which is a look and feel class
responsible for handling comboBox's input events and painting it.
|
void | showPopup()
This method displays popup with list of combo box's items on the screen |
void | updateUI()
This method sets this comboBox's UI to the UIManager's default for the
current look and feel. |
Note that the JComboBox will not change the value that is preselected by your ComboBoxModel implementation.
Parameters: model Data model that will be used by this JComboBox to keep track of its list of items.
Parameters: itemArray array containing list of items for this JComboBox
Parameters: itemVector vector containing list of items for this JComboBox.
Parameters: e the ActionEvent
Parameters: listener to add
A RuntimeException
is thrown if the data model is not
an instance of {@link MutableComboBoxModel}.
Parameters: element element to add
Parameters: listener to remove
Parameters: listener to add
Parameters: anEditor ComboBoxEditor to initialize anItem Item that should displayed in the specified editor
Parameters: a An Action to configure the combo box from
Parameters: event ListDataEvent describing the change
Parameters: action action to listen to for property changes
Returns: a PropertyChangeListener that listens to changes in action properties.
Returns: KeySelectionManager
Parameters: e the ItemEvent describing the change in the combo box's selection.
PopupMenuListeners
.
Note: This method is intended for use by plaf classes only.PopupMenuListeners
.
Note: This method is intended for use by plaf classes only.PopupMenuListeners
.
Note: This method is intended for use by plaf classes only.JComboBox
component.
Returns: The accessible context (an instance of {@link AccessibleJComboBox}).
Returns: Action
Returns: String actionCommand for the ActionEvent
Since: 1.4
Returns: ComboBoxEditor
Parameters: index index specifying location of the component to return.
Returns: component in the combo box that is located in the given index.
Returns: int number of elements in this JComboBox
Since: 1.4
Returns: JComboBox.KeySelectionManager
Returns: int maximun number of visible rows in the JComboBox's list.
Returns: ComboBoxModel containing items for this combo box.
Returns: The prototype display value (possibly null
).
Since: 1.4
See Also: setPrototypeDisplayValue
Returns: ListCellRenderer
Note: For performance reasons you should minimize invocation of this
method. If the data model is not an instance of
DefaultComboBoxModel
the complexity is O(n) where n is the
number of elements in the combo box.
Returns: int Index specifying location of the currently selected item in the combo box or -1 if nothing is selected in the combo box.
null
to indicate that nothing is
currently selected.
Returns: element that is currently selected in this combo box.
Returns: Object[] Object array of size 1 containing currently selected element in the JComboBox.
Returns: The UI used to display the JComboBox.
Returns: The String identifier for the UI class.
A RuntimeException
is thrown if the data model is not
an instance of {@link MutableComboBoxModel}.
Parameters: element element to insert index position where to insert the element
Parameters: event ListDataEvent describing the change
Parameters: event ListDataEvent describing the change.
Returns: boolean true if JComboBox is editable and false otherwise
Returns: boolean true if popup menu is lightweight and false otherwise.
Returns: boolean true if popup is visible and false otherwise
JComboBox
.
Returns: A string describing the attributes of this JComboBox
(never null
).
Parameters: e The KeyEvent indicating which key was pressed.
Parameters: listener ActionListener
A RuntimeException
is thrown if the data model is not an
instance of {@link MutableComboBoxModel}.
A RuntimeException
is thrown if the data model is not
an instance of {@link MutableComboBoxModel}.
Parameters: element element to remove
A RuntimeException
is thrown if the data model is not
an instance of {@link MutableComboBoxModel}.
Parameters: index index specifying position of the element to remove
Parameters: listener to remove
Parameters: listener to add
Parameters: keyChar character indicating which item in the combo box should be selected.
Returns: boolean true if item corresponding to the specified keyChar exists in the combo box. Otherwise false is returned.
Parameters: a action to set
Parameters: aCommand new action command for the JComboBox's ActionEvent
Parameters: editable indicates if the JComboBox's textfield should be editable or not.
Parameters: newEditor ComboBoxEditor for this JComboBox. This method fires PropertyChangeEvent when 'editor' property is changed.
Parameters: enabled if 'enabled' is true then enable JComboBox and disable it
Parameters: aManager
Parameters: enabled indicates if lightweight popup or heavyweight popup should be used to display JComboBox's elements.
Parameters: rowCount number of rows that will be visible in JComboBox's popup.
Parameters: newDataModel The new data model for this JComboBox
Parameters: visible show popup if 'visible' is true and hide it otherwise
prototypeDisplayValue
) is sent to all registered
listeners.
Parameters: value the new value (null
permitted).
Since: 1.4
See Also: getPrototypeDisplayValue
Parameters: aRenderer cell renderer that will be used by this JComboBox to paint its elements.
If the index is below -1 or exceeds the upper bound an
IllegalArgumentException
is thrown.
If the index is -1 then no item gets selected.
Parameters: index index specifying location of the component that should be selected.
Parameters: item element in the combo box to select.
Parameters: ui The new "UI" property