org.jdesktop.swingx.combobox
Class ListComboBoxModel<E>

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by org.jdesktop.swingx.combobox.ListComboBoxModel<E>
Type Parameters:
E - the type of elements maintained by the list backing this model
All Implemented Interfaces:
ActionListener, Serializable, EventListener, ComboBoxModel, ListModel
Direct Known Subclasses:
EnumComboBoxModel, MapComboBoxModel

public class ListComboBoxModel<E>
extends AbstractListModel
implements ComboBoxModel, ActionListener

A ComboBoxModel for Lists.

See Also:
Serialized Form

Field Summary
protected  List<E> data
          A reference to the list backing this model.
protected  E selected
          The currently selected item.
static String UPDATE
          A key used to notify the model that the backing List has changed.
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
ListComboBoxModel(List<E> list)
          Creates a ListComboBoxModel backed by the supplied list.
 
Method Summary
 void actionPerformed(ActionEvent evt)
          Invoked when an action occurs.
 E getElementAt(int index)
          Returns the value at the specified index.
 E getSelectedItem()
          Returns the selected item
 int getSize()
          Returns the length of the list.
 void setSelectedItem(Object item)
          Set the selected item.
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
 

Field Detail

UPDATE

public static final String UPDATE
A key used to notify the model that the backing List has changed.

See Also:
Constant Field Values

data

protected final List<E> data
A reference to the list backing this model.

This model does not make a copy of the list, so any changes in the list without synchronizing the model may have drastic effects.


selected

protected E selected
The currently selected item.

Constructor Detail

ListComboBoxModel

public ListComboBoxModel(List<E> list)
Creates a ListComboBoxModel backed by the supplied list.

Parameters:
list - the list backing this model
Throws:
NullPointerException - if list is null
Method Detail

setSelectedItem

public void setSelectedItem(Object item)
Set the selected item. The implementation of this method should notify all registered ListDataListeners that the contents have changed.

Specified by:
setSelectedItem in interface ComboBoxModel
Parameters:
item - the list object to select or null to clear the selection
Throws:
ClassCastException - if item is not of type E

getSelectedItem

public E getSelectedItem()
Returns the selected item

Specified by:
getSelectedItem in interface ComboBoxModel
Returns:
The selected item or null if there is no selection

getElementAt

public E getElementAt(int index)
Returns the value at the specified index.

Specified by:
getElementAt in interface ListModel
Parameters:
index - the requested index
Returns:
the value at index

getSize

public int getSize()
Returns the length of the list.

Specified by:
getSize in interface ListModel
Returns:
the length of the list

actionPerformed

public void actionPerformed(ActionEvent evt)
Invoked when an action occurs.

Specified by:
actionPerformed in interface ActionListener