|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JComboBox
public class JComboBox
A component that allows a user to select any item in its list and displays the selected item to the user. JComboBox also can show/hide a popup menu containing its list of item whenever the mouse is pressed over it.
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. |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
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. |
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 |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JComboBox()
Constructor. |
|
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. |
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. |
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 model)
Note that the JComboBox will not change the value that is preselected by your ComboBoxModel implementation.
model
- Data model that will be used by this JComboBox to keep track
of its list of items.public JComboBox(Object[] itemArray)
itemArray
- array containing list of items for this JComboBoxpublic JComboBox(Vector<?> itemVector)
itemVector
- vector containing list of items for this JComboBox.public JComboBox()
Method Detail |
---|
public boolean isEditable()
protected void installAncestorListener()
public void setUI(ComboBoxUI ui)
ui
- The new "UI" propertypublic void updateUI()
updateUI
in class JComponent
public String getUIClassID()
getUIClassID
in class JComponent
JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
public ComboBoxUI getUI()
public void setModel(ComboBoxModel newDataModel)
newDataModel
- The new data model for this JComboBoxpublic ComboBoxModel getModel()
public void setLightWeightPopupEnabled(boolean enabled)
enabled
- indicates if lightweight popup or heavyweight popup should
be used to display JComboBox's elements.public boolean isLightWeightPopupEnabled()
public void setEditable(boolean editable)
editable
- indicates if the JComboBox's textfield should be editable
or not.public void setMaximumRowCount(int rowCount)
rowCount
- number of rows that will be visible in JComboBox's popup.public int getMaximumRowCount()
public void setRenderer(ListCellRenderer aRenderer)
aRenderer
- cell renderer that will be used by this JComboBox to
paint its elements.public ListCellRenderer getRenderer()
public void setEditor(ComboBoxEditor newEditor)
newEditor
- ComboBoxEditor for this JComboBox. This method fires
PropertyChangeEvent when 'editor' property is changed.public ComboBoxEditor getEditor()
public void setSelectedItem(Object item)
item
- element in the combo box to select.public Object getSelectedItem()
null
to indicate that nothing is
currently selected.
public void setSelectedIndex(int index)
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.
index
- index specifying location of the component that should be
selected.public int getSelectedIndex()
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.
public Object getPrototypeDisplayValue()
null
).setPrototypeDisplayValue(Object)
public void setPrototypeDisplayValue(Object value)
PropertyChangeEvent
(with
the name prototypeDisplayValue
) is sent to all registered
listeners.
value
- the new value (null
permitted).getPrototypeDisplayValue()
public void addItem(Object element)
A RuntimeException
is thrown if the data model is not
an instance of MutableComboBoxModel
.
element
- element to addpublic void insertItemAt(Object element, int index)
A RuntimeException
is thrown if the data model is not
an instance of MutableComboBoxModel
.
element
- element to insertindex
- position where to insert the elementpublic void removeItem(Object element)
A RuntimeException
is thrown if the data model is not
an instance of MutableComboBoxModel
.
element
- element to removepublic void removeItemAt(int index)
A RuntimeException
is thrown if the data model is not
an instance of MutableComboBoxModel
.
index
- index specifying position of the element to removepublic void removeAllItems()
A RuntimeException
is thrown if the data model is not an
instance of MutableComboBoxModel
.
public void showPopup()
public void hidePopup()
public void setPopupVisible(boolean visible)
visible
- show popup if 'visible' is true and hide it otherwisepublic boolean isPopupVisible()
public void setActionCommand(String aCommand)
aCommand
- new action command for the JComboBox's ActionEventpublic String getActionCommand()
public void setAction(Action a)
a
- action to setpublic Action getAction()
protected void configurePropertiesFromAction(Action a)
a
- An Action to configure the combo box fromprotected PropertyChangeListener createActionPropertyChangeListener(Action action)
action
- action to listen to for property changes
protected void fireItemStateChanged(ItemEvent e)
e
- the ItemEvent describing the change in the combo box's
selection.protected void fireActionEvent()
public void firePopupMenuCanceled()
PopupMenuListeners
.
Note: This method is intended for use by plaf classes only.
public void firePopupMenuWillBecomeInvisible()
PopupMenuListeners
.
Note: This method is intended for use by plaf classes only.
public void firePopupMenuWillBecomeVisible()
PopupMenuListeners
.
Note: This method is intended for use by plaf classes only.
protected void selectedItemChanged()
public Object[] getSelectedObjects()
getSelectedObjects
in interface ItemSelectable
public void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
e
- the ActionEventpublic boolean selectWithKeyChar(char keyChar)
keyChar
- character indicating which item in the combo box should be
selected.
public void intervalAdded(ListDataEvent event)
intervalAdded
in interface ListDataListener
event
- ListDataEvent describing the changepublic void intervalRemoved(ListDataEvent event)
intervalRemoved
in interface ListDataListener
event
- ListDataEvent describing the change.public void contentsChanged(ListDataEvent event)
contentsChanged
in interface ListDataListener
event
- ListDataEvent describing the changepublic void setEnabled(boolean enabled)
setEnabled
in class JComponent
enabled
- if 'enabled' is true then enable JComboBox and disable itComponent.isEnabled()
,
Component.isLightweight()
public void configureEditor(ComboBoxEditor anEditor, Object anItem)
anEditor
- ComboBoxEditor to initializeanItem
- Item that should displayed in the specified editorpublic void processKeyEvent(KeyEvent e)
processKeyEvent
in class JComponent
e
- The KeyEvent indicating which key was pressed.KeyListener
,
Component.addKeyListener(KeyListener)
,
Component.enableEvents(long)
public void setKeySelectionManager(JComboBox.KeySelectionManager aManager)
aManager
- public JComboBox.KeySelectionManager getKeySelectionManager()
public int getItemCount()
public Object getItemAt(int index)
index
- index specifying location of the component to return.
protected JComboBox.KeySelectionManager createDefaultKeySelectionManager()
protected String paramString()
JComboBox
.
paramString
in class JComponent
JComboBox
(never null
).public AccessibleContext getAccessibleContext()
JComboBox
component.
getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
JComboBox.AccessibleJComboBox
).public void addActionListener(ActionListener listener)
listener
- to addpublic void removeActionListener(ActionListener listener)
listener
- ActionListenerpublic ActionListener[] getActionListeners()
public void addItemListener(ItemListener listener)
addItemListener
in interface ItemSelectable
listener
- to removepublic void removeItemListener(ItemListener listener)
removeItemListener
in interface ItemSelectable
listener
- to removepublic ItemListener[] getItemListeners()
public void addPopupMenuListener(PopupMenuListener listener)
listener
- to addpublic void removePopupMenuListener(PopupMenuListener listener)
listener
- to addpublic PopupMenuListener[] getPopupMenuListeners()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |