|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JComboBox
Swing's implementation of a ComboBox -- a combination of a text field and drop-down list that lets the user either type in a value or select it from a list that is displayed when the user asks for it. The editing capability can also be disabled so that the JComboBox acts only as a drop down list.
For the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JComboBox key assignments.
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. A future release of Swing will provide support for long term persistence.
Inner Class Summary | |
protected class |
JComboBox.AccessibleJComboBox
The class used to obtain the accessible role for this object. |
static interface |
JComboBox.KeySelectionManager
The interface that defines a KeySelectionManager. |
Inner classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
Field Summary | |
protected String |
actionCommand
|
protected ComboBoxModel |
dataModel
|
protected ComboBoxEditor |
editor
|
protected boolean |
isEditable
|
protected JComboBox.KeySelectionManager |
keySelectionManager
|
protected boolean |
lightWeightPopupEnabled
|
protected int |
maximumRowCount
|
protected ListCellRenderer |
renderer
|
protected Object |
selectedItemReminder
|
Fields inherited from class javax.swing.JComponent |
accessibleContext,
listenerList,
TOOL_TIP_TEXT_KEY,
ui,
UNDEFINED_CONDITION,
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
WHEN_FOCUSED,
WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT,
CENTER_ALIGNMENT,
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
TOP_ALIGNMENT |
Constructor Summary | |
JComboBox()
Creates a JComboBox with a default data model. |
|
JComboBox(ComboBoxModel aModel)
Creates a JComboBox that takes its items from an existing ComboBoxModel. |
|
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. |
Method Summary | |
void |
actionPerformed(ActionEvent e)
This method is public as an implementation side effect. |
void |
addActionListener(ActionListener l)
Adds an ActionListener. |
void |
addItem(Object anObject)
Adds an item to the item list. |
void |
addItemListener(ItemListener aListener)
Adds an ItemListener. |
void |
configureEditor(ComboBoxEditor anEditor,
Object anItem)
Initializes the editor with the specified item. |
void |
contentsChanged(ListDataEvent e)
This method is public as an implementation side effect. |
protected JComboBox.KeySelectionManager |
createDefaultKeySelectionManager()
Returns an instance of the default key-selection manager. |
protected void |
fireActionEvent()
Notify all listeners that have registered interest for notification on this event type. |
protected void |
fireItemStateChanged(ItemEvent e)
Notify all listeners that have registered interest for notification on this event type. |
AccessibleContext |
getAccessibleContext()
Get the AccessibleContext associated with this JComponent |
String |
getActionCommand()
Returns the action commnand that is included in the event sent to action listeners. |
ComboBoxEditor |
getEditor()
Returns the editor used to paint and edit the selected item in the JComboBox field. |
Object |
getItemAt(int index)
Returns the list item at the specified index. |
int |
getItemCount()
Returns the number of items in the list. |
JComboBox.KeySelectionManager |
getKeySelectionManager()
Returns the list's key-selection manager. |
int |
getMaximumRowCount()
Returns the maximum number of items the combo box can display without a scrollbar |
ComboBoxModel |
getModel()
Returns the data model currently used by the JComboBox. |
ListCellRenderer |
getRenderer()
Returns the renderer used to display the selected item in the JComboBox field. |
int |
getSelectedIndex()
Returns the index of the currently selected item in the list. |
Object |
getSelectedItem()
Returns the currently selected item. |
Object[] |
getSelectedObjects()
Returns an array containing the selected item. |
ComboBoxUI |
getUI()
Returns the L&F object that renders this component. |
String |
getUIClassID()
Returns the name of the L&F class that renders this component. |
void |
hidePopup()
Causes the combo box to close its popup window |
void |
insertItemAt(Object anObject,
int index)
Inserts an item into the item list at a given index. |
protected void |
installAncestorListener()
|
void |
intervalAdded(ListDataEvent e)
Invoked items have been added to the internal data model. |
void |
intervalRemoved(ListDataEvent e)
Invoked when values have been removed from the data model. |
boolean |
isEditable()
Returns true if the JComboBox is editable. |
boolean |
isFocusTraversable()
Returns true if the component can receive the focus. |
boolean |
isLightWeightPopupEnabled()
Returns true if lightweight (all-Java) popups are in use, or false if heavyweight (native peer) popups are being used. |
boolean |
isPopupVisible()
Determine the visibility of the popup |
protected String |
paramString()
Returns a string representation of this JComboBox. |
void |
processKeyEvent(KeyEvent e)
Handles KeyEvents, looking for the Tab key. |
void |
removeActionListener(ActionListener l)
Removes an ActionListener |
void |
removeAllItems()
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 at anIndex
This method works only if the JComboBox uses the default data model. |
void |
removeItemListener(ItemListener aListener)
Removes an ItemListener |
protected void |
selectedItemChanged()
This method is called when the selected item changes. |
boolean |
selectWithKeyChar(char keyChar)
Selects the list item that correponds to the specified keyboard character and returns true, if there is an item corresponding to that character. |
void |
setActionCommand(String aCommand)
Sets the action commnand that should be included in the event sent to action listeners. |
void |
setEditable(boolean aFlag)
Determines whether the JComboBox field is editable. |
void |
setEditor(ComboBoxEditor anEditor)
Sets the editor used to paint and edit the selected item in the JComboBox field. |
void |
setEnabled(boolean b)
Enables the combo box so that items can be selected. |
void |
setKeySelectionManager(JComboBox.KeySelectionManager aManager)
Sets the object that translates a keyboard character into a list selection. |
void |
setLightWeightPopupEnabled(boolean aFlag)
When displaying the popup, JComboBox choose to use a light weight popup if it fits. |
void |
setMaximumRowCount(int count)
Sets the maximum number of rows the JComboBox displays. |
void |
setModel(ComboBoxModel aModel)
Sets the data model that the JComboBox uses to obtain the list of items. |
void |
setPopupVisible(boolean v)
Set the visiblity of the popup |
void |
setRenderer(ListCellRenderer aRenderer)
Sets the renderer that paints the item selected from the list in the JComboBox field. |
void |
setSelectedIndex(int anIndex)
Selects the item at index anIndex . |
void |
setSelectedItem(Object anObject)
Sets the selected item in the JComboBox by specifying the object in the list. |
void |
setUI(ComboBoxUI ui)
Sets the L&F object that renders this component. |
void |
showPopup()
Causes the combo box to display its popup window |
void |
updateUI()
Notification from the UIFactory that the L&F has changed. |
Methods inherited from class java.awt.Container |
add,
add,
add,
add,
add,
addContainerListener,
addImpl,
countComponents,
deliverEvent,
doLayout,
findComponentAt,
findComponentAt,
getComponent,
getComponentAt,
getComponentAt,
getComponentCount,
getComponents,
getLayout,
insets,
invalidate,
isAncestorOf,
layout,
list,
list,
locate,
minimumSize,
paintComponents,
preferredSize,
print,
printComponents,
processContainerEvent,
processEvent,
remove,
remove,
removeAll,
removeContainerListener,
setCursor,
setLayout,
validate,
validateTree |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected ComboBoxModel dataModel
protected ListCellRenderer renderer
protected ComboBoxEditor editor
protected int maximumRowCount
protected boolean isEditable
protected Object selectedItemReminder
protected JComboBox.KeySelectionManager keySelectionManager
protected String actionCommand
protected boolean lightWeightPopupEnabled
Constructor Detail |
public JComboBox(ComboBoxModel aModel)
aModel
- the ComboBoxModel that provides the displayed list of itemspublic JComboBox(Object[] items)
public JComboBox(Vector items)
public JComboBox()
addItem
to add items.Method Detail |
protected void installAncestorListener()
public void setUI(ComboBoxUI ui)
ui
- the ComboBoxUI L&F objectUIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
JComponent.updateUI()
public String getUIClassID()
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
public ComboBoxUI getUI()
public void setModel(ComboBoxModel aModel)
aModel
- the ComboBoxModel that provides the displayed list of itemspublic ComboBoxModel getModel()
public void setLightWeightPopupEnabled(boolean aFlag)
public boolean isLightWeightPopupEnabled()
public void setEditable(boolean aFlag)
aFlag
- a boolean value, where true indicates that the field is editablepublic boolean isEditable()
public void setMaximumRowCount(int count)
count
- an int specifying the maximum number of items to display
in the list before using a scrollbarpublic int getMaximumRowCount()
public void setRenderer(ListCellRenderer aRenderer)
The default renderer displays a string, obtained
by calling the selected object's toString
method.
Other renderers can handle graphic images and composite items.
To display the selected item, aRenderer.getListCellRendererComponent
is called, passing the list object and an index of -1.
aRenderer
- the ListCellRenderer that displays the selected item.setEditor(javax.swing.ComboBoxEditor)
public ListCellRenderer getRenderer()
public void setEditor(ComboBoxEditor anEditor)
anEditor
- the ComboBoxEditor that displays the selected itemsetRenderer(javax.swing.ListCellRenderer)
public ComboBoxEditor getEditor()
public void setSelectedItem(Object anObject)
anObject
is in the list, the list displays with
anObject
selected. If the object does not exist in the list,
the default data model selects the first item in the list.anObject
- the list object to selectpublic Object getSelectedItem()
public void setSelectedIndex(int anIndex)
anIndex
.anIndex
- an int specifying the list item to select, where 0 specifies
the first item in the listpublic int getSelectedIndex()
public void addItem(Object anObject)
anObject
- the Object to add to the listpublic void insertItemAt(Object anObject, int index)
anObject
- the Object to add to the listindex
- an int specifying the position at which to add the itempublic void removeItem(Object anObject)
anObject
- the object to remove from the item listpublic void removeItemAt(int anIndex)
anIndex
This method works only if the JComboBox uses the default data model.
JComboBox uses the default data model when created with the
empty constructor and no other model has been set.anIndex
- an int specifying the idex of the item to remove, where 0
indicates the first item in the listpublic void removeAllItems()
public void showPopup()
setPopupVisible(boolean)
public void hidePopup()
setPopupVisible(boolean)
public void setPopupVisible(boolean v)
public boolean isPopupVisible()
public void addItemListener(ItemListener aListener)
aListener
will receive an event when
the selected item changes.aListener
- the ItemListener that is to be notifiedpublic void removeItemListener(ItemListener aListener)
aListener
- the ItemListener to removepublic void addActionListener(ActionListener l)
l
- the ActionListener that is to be notifiedpublic void removeActionListener(ActionListener l)
l
- the ActionListener to removepublic void setActionCommand(String aCommand)
aCommand
- a string containing the "command" that is sent
to action listeners. The same listener can then
do different things depending on the command it
receives.public String getActionCommand()
protected void fireItemStateChanged(ItemEvent e)
EventListenerList
protected void fireActionEvent()
EventListenerList
protected void selectedItemChanged()
public Object[] getSelectedObjects()
public void actionPerformed(ActionEvent e)
public void contentsChanged(ListDataEvent e)
ListDataListener
public boolean selectWithKeyChar(char keyChar)
keyChar
- a char, typically this is a keyboard key typed by the userpublic void intervalAdded(ListDataEvent e)
ListDataListener
public void intervalRemoved(ListDataEvent e)
ListDataListener
public void setEnabled(boolean b)
b
- a boolean value, where true enables the component and
false disables itpublic void configureEditor(ComboBoxEditor anEditor, Object anItem)
anEditor
- the ComboBoxEditor that displays the list item in the
combo box field and allows it to be editedanItem
- the object to display and edit in the fieldpublic void processKeyEvent(KeyEvent e)
e
- the KeyEvent containing the keyboard key that was pressedpublic boolean isFocusTraversable()
public void setKeySelectionManager(JComboBox.KeySelectionManager aManager)
public JComboBox.KeySelectionManager getKeySelectionManager()
public int getItemCount()
public Object getItemAt(int index)
index
- an int indicating the list position, where the first
item starts at zeroprotected JComboBox.KeySelectionManager createDefaultKeySelectionManager()
setKeySelectionManager(javax.swing.JComboBox.KeySelectionManager)
protected String paramString()
null
.public AccessibleContext getAccessibleContext()
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |