public class

DefaultComboBoxModel

extends AbstractListModel
implements Serializable MutableComboBoxModel
java.lang.Object
   ↳ javax.swing.AbstractListModel
     ↳ javax.swing.DefaultComboBoxModel

Class Overview

The default model for combo boxes.

Summary

[Expand]
Inherited Fields
From class javax.swing.AbstractListModel
Public Constructors
DefaultComboBoxModel()
Constructs an empty DefaultComboBoxModel object.
DefaultComboBoxModel(Object[] items)
Constructs a DefaultComboBoxModel object initialized with an array of objects.
DefaultComboBoxModel(Vector<?> v)
Constructs a DefaultComboBoxModel object initialized with a vector.
Public Methods
void addElement(Object anObject)
Adds an item at the end of the model.
Object 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(Object 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.
[Expand]
Inherited Methods
From class javax.swing.AbstractListModel
From class java.lang.Object
From interface javax.swing.ComboBoxModel
From interface javax.swing.ListModel
From interface javax.swing.MutableComboBoxModel

Public Constructors

public DefaultComboBoxModel ()

Constructs an empty DefaultComboBoxModel object.

public DefaultComboBoxModel (Object[] items)

Constructs a DefaultComboBoxModel object initialized with an array of objects.

Parameters
items an array of Object objects

public DefaultComboBoxModel (Vector<?> v)

Constructs a DefaultComboBoxModel object initialized with a vector.

Parameters
v a Vector object ...

Public Methods

public void addElement (Object anObject)

Adds an item at the end of the model. The implementation of this method should notify all registered ListDataListeners that the item has been added.

Parameters
anObject the Object to be added

public Object getElementAt (int index)

Returns the value at the specified index.

Parameters
index the requested index
Returns
  • the value at index

public int getIndexOf (Object anObject)

Returns the index-position of the specified object in the list.

Returns
  • an int representing the index position, where 0 is the first position

public Object getSelectedItem ()

Returns the selected item

Returns
  • The selected item or null if there is no selection

public int getSize ()

Returns the length of the list.

Returns
  • the length of the list

public void insertElementAt (Object anObject, int index)

Adds an item at a specific index. The implementation of this method should notify all registered ListDataListeners that the item has been added.

Parameters
anObject the Object to be added
index location to add the object

public void removeAllElements ()

Empties the list.

public void removeElement (Object anObject)

Removes an item from the model. The implementation of this method should should notify all registered ListDataListeners that the item has been removed.

Parameters
anObject the Object to be removed

public void removeElementAt (int index)

Removes an item at a specific index. The implementation of this method should notify all registered ListDataListeners that the item has been removed.

Parameters
index location of object to be removed

public void setSelectedItem (Object anObject)

Set the value of the selected item. The selected item may be null.

Parameters
anObject The combo box value or null for no selection.