GNU Classpath (0.95) | |
Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JComboBox
public class JComboBox
extends JComponent
implements ItemSelectable, ListDataListener, ActionListener, Accessible
Nested Class Summary | |
protected class |
|
static interface |
|
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 |
|
protected ComboBoxModel |
|
protected ComboBoxEditor |
|
protected boolean |
|
protected JComboBox.KeySelectionManager |
|
protected boolean |
|
protected int |
|
protected ListCellRenderer |
|
protected Object |
|
Fields inherited from class javax.swing.JComponent | |
TOOL_TIP_TEXT_KEY , UNDEFINED_CONDITION , WHEN_ANCESTOR_OF_FOCUSED_COMPONENT , WHEN_FOCUSED , WHEN_IN_FOCUSED_WINDOW , accessibleContext , listenerList , ui |
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 | |
| |
| |
|
Method Summary | |
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
protected void |
|
void |
|
protected PropertyChangeListener |
|
protected JComboBox.KeySelectionManager |
|
protected void |
|
protected void |
|
void |
|
void |
|
void |
|
AccessibleContext |
|
Action |
|
String |
|
ActionListener[] |
|
ComboBoxEditor |
|
Object |
|
int |
|
ItemListener[] |
|
JComboBox.KeySelectionManager |
|
int |
|
ComboBoxModel |
|
PopupMenuListener[] |
|
Object |
|
ListCellRenderer |
|
int |
|
Object |
|
Object[] |
|
ComboBoxUI |
|
String |
|
void |
|
void |
|
protected void | |
void |
|
void |
|
boolean |
|
boolean |
|
boolean |
|
protected String |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
boolean |
|
protected void |
|
void | |
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
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 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. This ListCellRenderer is used only when this JComboBox is uneditable.
protected Object selectedItemReminder
This field is reference to the current selection of the combo box.
public JComboBox()
Constructor. Creates new empty JComboBox. ComboBox's data model is set to DefaultComboBoxModel.
public JComboBox(Vector> itemVector)
Constructs JComboBox object with specified list of items.
- Parameters:
itemVector
- vector containing list of items for this JComboBox.
public JComboBox(Object[] itemArray)
Constructs JComboBox with specified list of items.
- Parameters:
itemArray
- array containing list of items for this JComboBox
public JComboBox(ComboBoxModel model)
Constructs JComboBox object with specified data model for it. 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.
public void actionPerformed(ActionEvent e)
This method handles actionEvents fired by the ComboBoxEditor. It changes this JComboBox's selection to the new value currently in the editor and hides list of combo box items.
- Specified by:
- actionPerformed in interface ActionListener
- Parameters:
e
- the ActionEvent
public void addActionListener(ActionListener listener)
This methods adds specified ActionListener to this JComboBox.
- Parameters:
listener
- to add
public void addItem(Object element)
This method adds given element to this JComboBox. ARuntimeException
is thrown if the data model is not an instance ofMutableComboBoxModel
.
- Parameters:
element
- element to add
public void addItemListener(ItemListener listener)
This method registers given ItemListener with this JComboBox
- Specified by:
- addItemListener in interface ItemSelectable
- Parameters:
listener
- to remove
public 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
- Parameters:
listener
- to add
public void configureEditor(ComboBoxEditor anEditor, Object anItem)
This method initializes specified ComboBoxEditor to display given item.
- Parameters:
anEditor
- ComboBoxEditor to initializeanItem
- Item that should displayed in the specified editor
protected void configurePropertiesFromAction(Action a)
Configure properties of the JComboBox by reading properties of specified action. This method always sets the comboBox's "enabled" property to the value of the Action's "enabled" property.
- Parameters:
a
- An Action to configure the combo box from
public void contentsChanged(ListDataEvent event)
The part of implementation of ListDataListener interface. This method is invoked when contents of the JComboBox's data model changed.
- Specified by:
- contentsChanged in interface ListDataListener
- Parameters:
event
- ListDataEvent describing the change
protected PropertyChangeListener createActionPropertyChangeListener(Action action)
Creates PropertyChangeListener to listen for the changes in comboBox's action properties.
- Parameters:
action
- action to listen to for property changes
- Returns:
- a PropertyChangeListener that listens to changes in action properties.
protected JComboBox.KeySelectionManager createDefaultKeySelectionManager()
createDefaultKeySelectionManager
- Returns:
- KeySelectionManager
protected void fireActionEvent()
This method fires ActionEvent to this JComboBox's registered ActionListeners. This method is invoked when user explicitly changes currently selected item.
protected void fireItemStateChanged(ItemEvent e)
This method fires ItemEvent to this JComboBox's registered ItemListeners. This method is invoked when currently selected item in this combo box has changed.
- Parameters:
e
- the ItemEvent describing the change in the combo box's selection.
public void firePopupMenuCanceled()
Fires a popupMenuCanceled() event to allPopupMenuListeners
. Note: This method is intended for use by plaf classes only.
public void firePopupMenuWillBecomeInvisible()
Fires a popupMenuWillBecomeInvisible() event to allPopupMenuListeners
. Note: This method is intended for use by plaf classes only.
public void firePopupMenuWillBecomeVisible()
Fires a popupMenuWillBecomeVisible() event to allPopupMenuListeners
. Note: This method is intended for use by plaf classes only.
public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for thisJComboBox
component.
- Specified by:
- getAccessibleContext in interface Accessible
- Overrides:
- getAccessibleContext in interface JComponent
- Returns:
- The accessible context (an instance of
JComboBox.AccessibleJComboBox
).
public Action getAction()
This method returns Action that is invoked when selected item is changed in the JComboBox.
- Returns:
- Action
public String getActionCommand()
Returns actionCommand associated with the ActionEvent fired by the JComboBox to its registered ActionListeners.
- Returns:
- String actionCommand for the ActionEvent
public ActionListener[] getActionListeners()
This method returns array of ActionListeners that are registered with this JComboBox.
- Since:
- 1.4
public ComboBoxEditor getEditor()
Returns editor component that is responsible for displaying/editing selected item in the combo box.
- Returns:
- ComboBoxEditor
public Object getItemAt(int index)
Returns elements located in the combo box at the given index.
- Parameters:
index
- index specifying location of the component to return.
- Returns:
- component in the combo box that is located in the given index.
public int getItemCount()
This method returns number of elements in this JComboBox
- Returns:
- int number of elements in this JComboBox
public ItemListener[] getItemListeners()
This method returns array of ItemListeners that are registered with this JComboBox.
- Since:
- 1.4
public JComboBox.KeySelectionManager getKeySelectionManager()
getKeySelectionManager
- Returns:
- JComboBox.KeySelectionManager
public int getMaximumRowCount()
This method returns number of rows visible in the JComboBox's list of items.
- Returns:
- int maximun number of visible rows in the JComboBox's list.
public ComboBoxModel getModel()
This method returns data model for this comboBox.
- Returns:
- ComboBoxModel containing items for this combo box.
public PopupMenuListener[] getPopupMenuListeners()
Returns array of PopupMenuListeners that are registered with combo box.
public Object getPrototypeDisplayValue()
Returns an object that is used as the display value when calculating the preferred size for the combo box. This value is, of course, never displayed anywhere.
- Returns:
- The prototype display value (possibly
null
).
- Since:
- 1.4
- See Also:
setPrototypeDisplayValue(Object)
public ListCellRenderer getRenderer()
This method returns renderer responsible for rendering selected item in the combo box
- Returns:
- ListCellRenderer
public int getSelectedIndex()
Returns index of the item that is currently selected in the combo box. If no item is currently selected, then -1 is returned. Note: For performance reasons you should minimize invocation of this method. If the data model is not an instance ofDefaultComboBoxModel
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.
public Object getSelectedItem()
Returns currently selected item in the combo box. The result may benull
to indicate that nothing is currently selected.
- Returns:
- element that is currently selected in this combo box.
public Object[] getSelectedObjects()
Returns Object array of size 1 containing currently selected element in the JComboBox.
- Specified by:
- getSelectedObjects in interface ItemSelectable
- Returns:
- Object[] Object array of size 1 containing currently selected element in the JComboBox.
public ComboBoxUI getUI()
This method returns the UI used to display the JComboBox.
- Returns:
- The UI used to display the JComboBox.
public String getUIClassID()
This method returns the String identifier for the UI class to the used with the JComboBox.
- Overrides:
- getUIClassID in interface JComponent
- Returns:
- The String identifier for the UI class.
public void insertItemAt(Object element, int index)
Inserts given element at the specified index to this JComboBox. ARuntimeException
is thrown if the data model is not an instance ofMutableComboBoxModel
.
- Parameters:
element
- element to insertindex
- position where to insert the element
public void intervalAdded(ListDataEvent event)
The part of implementation of ListDataListener interface. This method is invoked when some items where added to the JComboBox's data model.
- Specified by:
- intervalAdded in interface ListDataListener
- Parameters:
event
- ListDataEvent describing the change
public void intervalRemoved(ListDataEvent event)
The part of implementation of ListDataListener interface. This method is invoked when some items where removed from the JComboBox's data model.
- Specified by:
- intervalRemoved in interface ListDataListener
- Parameters:
event
- ListDataEvent describing the change.
public boolean isEditable()
This method returns true JComboBox is editable and false otherwise
- Returns:
- boolean true if JComboBox is editable and false otherwise
public boolean isLightWeightPopupEnabled()
This method returns whether popup menu that is used to display list of combo box's item is lightWeight or not.
- Returns:
- boolean true if popup menu is lightweight and false otherwise.
public boolean isPopupVisible()
Checks if popup is currently visible on the screen.
- Returns:
- boolean true if popup is visible and false otherwise
protected String paramString()
Returns an implementation-dependent string describing the attributes of thisJComboBox
.
- Overrides:
- paramString in interface JComponent
- Returns:
- A string describing the attributes of this
JComboBox
(nevernull
).
public void processKeyEvent(KeyEvent e)
This method is fired whenever a key is pressed with the combo box in focus
- Overrides:
- processKeyEvent in interface JComponent
- Parameters:
e
- The KeyEvent indicating which key was pressed.
public void removeActionListener(ActionListener listener)
This method removes specified ActionListener from this JComboBox.
- Parameters:
listener
- ActionListener
public void removeAllItems()
This method removes all elements from this JComboBox. ARuntimeException
is thrown if the data model is not an instance ofMutableComboBoxModel
.
public void removeItem(Object element)
This method removes given element from this JComboBox. ARuntimeException
is thrown if the data model is not an instance ofMutableComboBoxModel
.
- Parameters:
element
- element to remove
public void removeItemAt(int index)
This method remove element location in the specified index in the JComboBox. ARuntimeException
is thrown if the data model is not an instance ofMutableComboBoxModel
.
- Parameters:
index
- index specifying position of the element to remove
public void removeItemListener(ItemListener listener)
This method unregisters given ItemListener from this JComboBox
- Specified by:
- removeItemListener in interface ItemSelectable
- Parameters:
listener
- to remove
public 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
- Parameters:
listener
- to add
public 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. Otherwise false is returned.
- 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.
protected void selectedItemChanged()
This method is invoked whenever selected item changes in the combo box's data model. It fires ItemEvent and ActionEvent to all registered ComboBox's ItemListeners and ActionListeners respectively, indicating the change.
public void setActionCommand(String aCommand)
This method sets actionCommand to the specified string. ActionEvent fired to this JComboBox registered ActionListeners will contain this actionCommand.
- Parameters:
aCommand
- new action command for the JComboBox's ActionEvent
public void setEditable(boolean editable)
This method sets editability of the combo box. If combo box is editable the user can choose component from the combo box list by typing component's name in the editor(JTextfield by default). Otherwise if not editable, the user should use the list to choose the component. This method fires PropertyChangeEvents to JComboBox's registered PropertyChangeListeners to indicate that 'editable' property of the JComboBox has changed.
- Parameters:
editable
- indicates if the JComboBox's textfield should be editable or not.
public void setEditor(ComboBoxEditor newEditor)
Sets editor for this JComboBox
- Parameters:
newEditor
- ComboBoxEditor for this JComboBox. This method fires PropertyChangeEvent when 'editor' property is changed.
public void setEnabled(boolean enabled)
This method disables or enables JComboBox. If the JComboBox is enabled, then user is able to make item choice, otherwise if JComboBox is disabled then user is not able to make a selection.
- Overrides:
- setEnabled in interface JComponent
- Parameters:
enabled
- if 'enabled' is true then enable JComboBox and disable it
public void setKeySelectionManager(JComboBox.KeySelectionManager aManager)
setKeySelectionManager
- Parameters:
aManager
-
public void setLightWeightPopupEnabled(boolean enabled)
This method sets JComboBox's popup to be either lightweight or heavyweight. If 'enabled' is true then lightweight popup is used and heavyweight otherwise. By default lightweight popup is used to display this JComboBox's elements.
- Parameters:
enabled
- indicates if lightweight popup or heavyweight popup should be used to display JComboBox's elements.
public void setMaximumRowCount(int rowCount)
Sets number of rows that should be visible in this JComboBox's popup. If this JComboBox's popup has more elements that maximum number or rows then popup will have a scroll pane to allow users to view other elements.
- Parameters:
rowCount
- number of rows that will be visible in JComboBox's popup.
public void setModel(ComboBoxModel newDataModel)
Set the data model for this JComboBox. This un-registers all listeners associated with the current model, and re-registers them with the new model.
- Parameters:
newDataModel
- The new data model for this JComboBox
public void setPopupVisible(boolean visible)
This method either displayes or hides the popup containing list of combo box's items.
- Parameters:
visible
- show popup if 'visible' is true and hide it otherwise
public void setPrototypeDisplayValue(Object value)
Sets the object that is assumed to be the displayed item when calculating the preferred size for the combo box. APropertyChangeEvent
(with the nameprototypeDisplayValue
) is sent to all registered listeners.
- Parameters:
value
- the new value (null
permitted).
- Since:
- 1.4
- See Also:
getPrototypeDisplayValue()
public void setRenderer(ListCellRenderer aRenderer)
This method sets cell renderer for this JComboBox that will be used to paint combo box's items. The Renderer should only be used only when JComboBox is not editable. In the case when JComboBox is editable the editor must be used. This method also fires PropertyChangeEvent when cellRendered for this JComboBox has changed.
- Parameters:
aRenderer
- cell renderer that will be used by this JComboBox to paint its elements.
public void setSelectedIndex(int index)
Forces JComboBox to select component located in the given index in the combo box. If the index is below -1 or exceeds the upper bound anIllegalArgumentException
is thrown. If the index is -1 then no item gets selected.
- Parameters:
index
- index specifying location of the component that should be selected.
public void setSelectedItem(Object item)
Forces combo box to select given item
- Parameters:
item
- element in the combo box to select.
public 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.
- Parameters:
ui
- The new "UI" property
public void showPopup()
This method displays popup with list of combo box's items on the screen
public void updateUI()
This method sets this comboBox's UI to the UIManager's default for the current look and feel.
- Overrides:
- updateUI in interface JComponent
GNU Classpath (0.95) |