E
- the element type of the underlying list and this modelpublic class ListBackedComboBoxModel<E> extends ListBackedListModel<E> implements javax.swing.ComboBoxModel<E>
ComboBoxModel
that always reflects the contents of a List
.
Note that this model does reflect changes in the underlying list that occur after the creation of this object but will not inform its
listeners on these. (The underlying list cannot be monitored.) The methods ListBackedListModel.add(Object)
, ListBackedListModel.add(int, Object)
,
ListBackedListModel.set(int, Object)
, ListBackedListModel.remove(int)
and ListBackedListModel.clear()
allow to edit the underlying list and notify all listeners
registered to this model and the same time. It is recommended to use these methods instead of modifying the list directly if changes
should be made to a list that is currently displayed in the GUI, e.g., in an instance of JList
.
Constructor and Description |
---|
ListBackedComboBoxModel(java.util.List<E> list) |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getSelectedItem() |
void |
setSelectedItem(java.lang.Object selectedItem)
Sets the selected item of this model.
|
add, add, clear, getElementAt, getList, getSize, remove, set, setList
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
public ListBackedComboBoxModel(java.util.List<E> list)
public java.lang.Object getSelectedItem()
getSelectedItem
in interface javax.swing.ComboBoxModel<E>
public void setSelectedItem(java.lang.Object selectedItem)
Selected items do not necessarily have to be part of the underlying list.
When this method is called a the event ListDataListener.contentsChanged(javax.swing.event.ListDataEvent)
is fired with the
start and end indices -1
. (This behavior is identical with DefaultComboBoxModel
).
setSelectedItem
in interface javax.swing.ComboBoxModel<E>
selectedItem
- the item to be selected from now on