charvax.swing

Class JComboBox

Implemented Interfaces:
EventListener, ItemSelectable, ListSelectionListener

public class JComboBox
extends JComponent
implements ListSelectionListener, ItemSelectable

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.

Field Summary

protected Vector
_actionListeners
A list of ActionListeners registered for this component.
protected Vector
_itemListeners
A list of ItemListeners registered for this component.

Fields inherited from class charvax.swing.JComponent

_border

Fields inherited from class charva.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT, _alignmentX, _alignmentY, _background, _cursesColor, _enabled, _focusListeners, _foreground, _keyListeners, _origin, _parent, _visible

Constructor Summary

JComboBox()
Creates an empty JComboBox.
JComboBox(Object[] items_)
Creates a JComboBox that contains the elements in the specified array.
JComboBox(Vector items_)
Creates a JComboBox that contains the elements in the specified Vector.
JComboBox(ComboBoxModel model)
Creates a JComboBox with the given model.

Method Summary

void
addActionListener(ActionListener al_)
Register an ActionListener object for this component.
void
addItem(Object item_)
Add the specified item into the list of items.
void
addItemListener(ItemListener il_)
Register an ItemListener object for this component.
void
debug(int level_)
Output a description of this component to stderr.
void
draw()
Draw the selected item, surrounded by a box.
protected void
fireActionEvent(ActionEvent ae_)
Invoke all the ActionListener callbacks that may have been registered for this component.
protected void
fireItemStateChanged(ItemEvent ie_)
Invoke all the ItemListener callbacks that may have been registered for this component.
int
getHeight()
Object
getSelectedItem()
Returns the selected item.
Dimension
getSize()
int
getWidth()
Returns width (including the diamond symbol).
void
insertItemAt(Object item_, int index_)
Insert the specified item at the specified index.
Dimension
minimumSize()
void
processEvent(AWTEvent evt_)
Overrides method in superclass.
void
processKeyEvent(KeyEvent ke_)
Process KeyEvents that have been generated by this JComboBox component.
void
processMouseEvent(MouseEvent e_)
Process a MouseEvent that was generated by clicking the mouse on this JComboBox.
void
removeAllItems()
Removes all items.
void
removeItem(Object item_)
Removes the specified item from the combobox's list.
void
removeItemAt(int index_)
Remove the item at the specified index.
void
removeItemListener(ItemListener listener_)
void
requestFocus()
This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.
void
setEditable(boolean editable)
Make the combobox editable.
void
setMaximumRowCount(int rows_)
Sets the maximum number of rows that the JComboBox displays.
void
setModel(ComboBoxModel model_)
Sets the data model that the JComboBox uses to obtain the list of items.
void
setSelectedIndex(int index_)
Sets the selected item in the JComboBox by specifying the index in the list.
void
setSelectedItem(Object obj_)
Sets the selected item in the JComboBox by specifying the object in the list.
String
toString()
Returns a String representation of this component.
void
valueChanged(ListSelectionEvent e_)
Implements the ListSelectionListener interface.

Methods inherited from class charvax.swing.JComponent

draw, getBorder, getInsets, setBorder

Methods inherited from class charva.awt.Component

addFocusListener, addKeyListener, contains, contains, debug, draw, getAlignmentX, getAlignmentY, getAncestorWindow, getBackground, getBounds, getCursesColor, getForeground, getHeight, getLocation, getLocationOnScreen, getName, getParent, getSize, getWidth, hasFocus, hide, invalidate, isDisplayed, isEnabled, isFocusTraversable, isTotallyObscured, isValid, isVisible, minimumSize, processEvent, processFocusEvent, processKeyEvent, processMouseEvent, repaint, requestFocus, requestSync, setBackground, setEnabled, setForeground, setLocation, setLocation, setName, setParent, setVisible, show, validate, validateCursesColor

Field Details

_actionListeners

protected Vector _actionListeners
A list of ActionListeners registered for this component.

_itemListeners

protected Vector _itemListeners
A list of ItemListeners registered for this component.

Constructor Details

JComboBox

public JComboBox()
Creates an empty JComboBox.

JComboBox

public JComboBox(Object[] items_)
Creates a JComboBox that contains the elements in the specified array.
Parameters:
items_ - the array of items to display in the combobox

JComboBox

public JComboBox(Vector items_)
Creates a JComboBox that contains the elements in the specified Vector.
Parameters:
items_ - the vector of items to display in the combobox

JComboBox

public JComboBox(ComboBoxModel model)
Creates a JComboBox with the given model.

Method Details

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).


addItemListener

public void addItemListener(ItemListener il_)
Register an ItemListener object for this component.
Specified by:
addItemListener in interface ItemSelectable

debug

public void debug(int level_)
Output a description of this component to stderr.
Overrides:
debug in interface Component

draw

public void draw()
Draw the selected item, surrounded by a box.
Overrides:
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.

getHeight

public int getHeight()
Overrides:
getHeight in interface Component

getSelectedItem

public Object getSelectedItem()
Returns the selected item.

getSize

public Dimension getSize()
Overrides:
getSize in interface Component

getWidth

public int getWidth()
Returns width (including the diamond symbol).
Overrides:
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).


minimumSize

public Dimension minimumSize()
Overrides:
minimumSize in interface Component

processEvent

public void processEvent(AWTEvent evt_)
Overrides method in superclass.
Overrides:
processEvent in interface Component

processKeyEvent

public void processKeyEvent(KeyEvent ke_)
Process KeyEvents that have been generated by this JComboBox component.
Overrides:
processKeyEvent in interface Component

processMouseEvent

public void processMouseEvent(MouseEvent e_)
Process a MouseEvent that was generated by clicking the mouse on this JComboBox.
Overrides:
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).


removeItemListener

public void removeItemListener(ItemListener listener_)
Specified by:
removeItemListener in interface ItemSelectable

requestFocus

public void requestFocus()
This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.
Overrides:
requestFocus in interface Component

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.

valueChanged

public void valueChanged(ListSelectionEvent e_)
Implements the ListSelectionListener interface.
Specified by:
valueChanged in interface ListSelectionListener