E - the type of the elements of this modelpublic class DefaultComboBoxModel<E> extends AbstractListModel<E> implements MutableComboBoxModel<E>, Serializable
listenerList| Constructor | Description |
|---|---|
DefaultComboBoxModel() |
Constructs an empty DefaultComboBoxModel object.
|
DefaultComboBoxModel(E[] items) |
Constructs a DefaultComboBoxModel object initialized with
an array of objects.
|
DefaultComboBoxModel(Vector<E> v) |
Constructs a DefaultComboBoxModel object initialized with
a vector.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addElement(E anObject) |
Adds an item at the end of the model.
|
E |
getElementAt(int index) |
Returns the value at the specified index.
|
int |
getIndexOf(Object anObject) |
Returns the index-position of the specified object in the list.
|
Object |
getSelectedItem() |
Returns the selected item
|
int |
getSize() |
Returns the length of the list.
|
void |
insertElementAt(E anObject,
int index) |
Adds an item at a specific index.
|
void |
removeAllElements() |
Empties the list.
|
void |
removeElement(Object anObject) |
Removes an item from the model.
|
void |
removeElementAt(int index) |
Removes an item at a specific index.
|
void |
setSelectedItem(Object anObject) |
Set the value of the selected item.
|
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListenerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddListDataListener, removeListDataListenerpublic DefaultComboBoxModel()
public DefaultComboBoxModel(E[] items)
items - an array of Object objectspublic void setSelectedItem(Object anObject)
setSelectedItem in interface ComboBoxModel<E>anObject - The combo box value or null for no selection.public Object getSelectedItem()
ComboBoxModelgetSelectedItem in interface ComboBoxModel<E>null if there is no selectionpublic int getSize()
ListModelpublic E getElementAt(int index)
ListModelgetElementAt in interface ListModel<E>index - the requested indexindexpublic int getIndexOf(Object anObject)
anObject - public void addElement(E anObject)
MutableComboBoxModelListDataListeners that the
item has been added.addElement in interface MutableComboBoxModel<E>anObject - the item to be addedpublic void insertElementAt(E anObject, int index)
MutableComboBoxModelListDataListeners that the
item has been added.insertElementAt in interface MutableComboBoxModel<E>anObject - the item to be addedindex - location to add the objectpublic void removeElementAt(int index)
MutableComboBoxModelListDataListeners that the
item has been removed.removeElementAt in interface MutableComboBoxModel<E>index - location of the item to be removedpublic void removeElement(Object anObject)
MutableComboBoxModelListDataListeners that the
item has been removed.removeElement in interface MutableComboBoxModel<E>anObject - the Object to be removedpublic void removeAllElements()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Scripting on this page tracks web page traffic, but does not change the content in any way.