E
- the type of the elements of this modelSerializable
, ComboBoxModel<E>
, ListModel<E>
, MutableComboBoxModel<E>
public class DefaultComboBoxModel<E> extends AbstractListModel<E> implements MutableComboBoxModel<E>, Serializable
listenerList
Constructor | Description |
---|---|
DefaultComboBoxModel() |
Constructs an empty DefaultComboBoxModel object. |
DefaultComboBoxModel |
Constructs a DefaultComboBoxModel object initialized with an array of objects. |
DefaultComboBoxModel |
Constructs a DefaultComboBoxModel object initialized with a vector. |
Modifier and Type | Method | Description |
---|---|---|
void |
addAll |
Adds all of the elements present in the collection, starting from the specified index. |
void |
addAll |
Adds all of the elements present in the collection. |
void |
addElement |
Adds an item at the end of the model. |
E |
getElementAt |
Returns the value at the specified index. |
int |
getIndexOf |
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 |
Adds an item at a specific index. |
void |
removeAllElements() |
Empties the list. |
void |
removeElement |
Removes an item from the model. |
void |
removeElementAt |
Removes an item at a specific index. |
void |
setSelectedItem |
Set the value of the selected item. |
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addListDataListener, removeListDataListener
public DefaultComboBoxModel()
public DefaultComboBoxModel(E[] items)
items
- an array of Object objectspublic DefaultComboBoxModel(Vector<E> v)
v
- a Vector object ...public void setSelectedItem(Object anObject)
setSelectedItem
in interface ComboBoxModel<E>
anObject
- The combo box value or null for no selection.public Object getSelectedItem()
ComboBoxModel
getSelectedItem
in interface ComboBoxModel<E>
null
if there is no selectionpublic int getSize()
ListModel
public E getElementAt(int index)
ListModel
getElementAt
in interface ListModel<E>
index
- the requested indexindex
public int getIndexOf(Object anObject)
anObject
- the object to return the index ofpublic void addElement(E anObject)
MutableComboBoxModel
ListDataListener
s that the item has been added.addElement
in interface MutableComboBoxModel<E>
anObject
- the item to be addedpublic void insertElementAt(E anObject, int index)
MutableComboBoxModel
ListDataListener
s 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)
MutableComboBoxModel
ListDataListener
s that the item has been removed.removeElementAt
in interface MutableComboBoxModel<E>
index
- location of the item to be removedpublic void removeElement(Object anObject)
MutableComboBoxModel
ListDataListener
s that the item has been removed.removeElement
in interface MutableComboBoxModel<E>
anObject
- the Object
to be removedpublic void removeAllElements()
public void addAll(Collection<? extends E> c)
c
- the collection which contains the elements to addNullPointerException
- if c
is nullpublic void addAll(int index, Collection<? extends E> c)
index
- index at which to insert the first element from the specified collectionc
- the collection which contains the elements to addArrayIndexOutOfBoundsException
- if index
does not fall within the range of number of elements currently heldNullPointerException
- if c
is null
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/javax/swing/DefaultComboBoxModel.html