The JComboBox component allows the user to select an item from a pop-up
list of choices.
When the combobox is in a non-popped-up state, it looks like a JButton
with a "diamond" character on the right. To make the popup menu appear,
the user positions the cursor over the combobox and presses ENTER.
When the user selects an item in the popup menu (by positioning the
cursor on it and pressing ENTER), the pop-up menu disappears and
only the selected item is shown. At the same time the JComboBox
posts an ActionEvent onto the system event queue. The "action command"
encapsulated in the ActionEvent is the list item that was selected.
Note that this class provides an "Uneditable" JComboBox only.
addActionListener
public void addActionListener(ActionListener al_)
Register an ActionListener object for this component.
addItem
public void addItem(Object item_)
Add the specified item into the list of items.
Note that this method works only if the data model is
a MutableComboBoxModel (by default, it is).
debug
public void debug(int level_)
Output a description of this component to stderr.
- debug in interface Component
draw
public void draw()
Draw the selected item, surrounded by a box.
- draw in interface JComponent
fireActionEvent
protected void fireActionEvent(ActionEvent ae_)
Invoke all the ActionListener callbacks that may have been registered
for this component.
fireItemStateChanged
protected void fireItemStateChanged(ItemEvent ie_)
Invoke all the ItemListener callbacks that may have been registered
for this component.
getSelectedItem
public Object getSelectedItem()
Returns the selected item.
getWidth
public int getWidth()
Returns width (including the diamond symbol).
- getWidth in interface Component
insertItemAt
public void insertItemAt(Object item_,
int index_)
Insert the specified item at the specified index.
Note that this method works only if the data model is
a MutableComboBoxModel (by default, it is).
processKeyEvent
public void processKeyEvent(KeyEvent ke_)
Process KeyEvents that have been generated by this JComboBox component.
- processKeyEvent in interface Component
processMouseEvent
public void processMouseEvent(MouseEvent e_)
Process a MouseEvent that was generated by clicking the mouse
on this JComboBox.
- processMouseEvent in interface Component
removeAllItems
public void removeAllItems()
Removes all items.
Note that this method works only if the data model is
a MutableComboBoxModel (by default, it is).
removeItem
public void removeItem(Object item_)
Removes the specified item from the combobox's list. If the
item was not in the list, the list is not changed.
Note that this method works only if the data model is
a MutableComboBoxModel (by default, it is).
removeItemAt
public void removeItemAt(int index_)
Remove the item at the specified index.
Note that this method works only if the data model is
a MutableComboBoxModel (by default, it is).
setEditable
public void setEditable(boolean editable)
Make the combobox editable.
setMaximumRowCount
public void setMaximumRowCount(int rows_)
Sets the maximum number of rows that the JComboBox displays.
setModel
public void setModel(ComboBoxModel model_)
Sets the data model that the JComboBox uses to obtain the list of
items.
setSelectedIndex
public void setSelectedIndex(int index_)
Sets the selected item in the JComboBox by specifying
the index in the list.
setSelectedItem
public void setSelectedItem(Object obj_)
Sets the selected item in the JComboBox by specifying the
object in the list.
toString
public String toString()
Returns a String representation of this component.