Package org.jdesktop.swingx.combobox
Class ListComboBoxModel<E>
- java.lang.Object
-
- javax.swing.AbstractListModel
-
- 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
AComboBoxModelforLists.- Author:
- jm158417, Karl George Schaefer
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected List<E>dataA reference to the list backing this model.protected EselectedThe currently selected item.static StringUPDATEA key used to notify the model that the backingListhas changed.-
Fields inherited from class javax.swing.AbstractListModel
listenerList
-
-
Constructor Summary
Constructors Constructor Description ListComboBoxModel(List<E> list)Creates aListComboBoxModelbacked by the suppliedlist.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(ActionEvent evt)EgetElementAt(int index)EgetSelectedItem()intgetSize()voidsetSelectedItem(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 backingListhas 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 aListComboBoxModelbacked by the suppliedlist.- Parameters:
list- the list backing this model- Throws:
NullPointerException- iflistisnull
-
-
Method Detail
-
setSelectedItem
public void setSelectedItem(Object item)
Set the selected item. The implementation of this method should notify all registeredListDataListeners that the contents have changed.- Specified by:
setSelectedItemin interfaceComboBoxModel<E>- Parameters:
item- the list object to select ornullto clear the selection- Throws:
ClassCastException- ifitemis not of typeE
-
getSelectedItem
public E getSelectedItem()
- Specified by:
getSelectedItemin interfaceComboBoxModel<E>
-
getElementAt
public E getElementAt(int index)
- Specified by:
getElementAtin interfaceListModel<E>
-
actionPerformed
public void actionPerformed(ActionEvent evt)
- Specified by:
actionPerformedin interfaceActionListener
-
-