Package org.jdesktop.swingx.combobox
Class MapComboBoxModel<K,V>
- java.lang.Object
-
- javax.swing.AbstractListModel
-
- org.jdesktop.swingx.combobox.ListComboBoxModel<K>
-
- org.jdesktop.swingx.combobox.MapComboBoxModel<K,V>
-
- Type Parameters:
K- the type of keys maintained by the map backing this modelV- the type of mapped values
- All Implemented Interfaces:
java.awt.event.ActionListener,java.io.Serializable,java.util.EventListener,javax.swing.ComboBoxModel,javax.swing.ListModel
public class MapComboBoxModel<K,V> extends ListComboBoxModel<K>
AComboBoxModelforMaps. The model will always present aMapconsistently, once it is instantiated. However, unless theMapis ordered, as ajava.util.TreeMapis, the model is not guaranteed to present the maps in a consistent order between instantiations.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MapComboBoxModel()Creates an empty model.MapComboBoxModel(java.util.Map<K,V> map)Creates a model backed by the specified map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent evt)private static <E> java.util.List<E>buildIndex(java.util.Map<E,?> map)Builds an index for this model.intgetSize()VgetValue(int selectedItem)Selects an item from the model and returns that map value.VgetValue(java.lang.Object selectedItem)Selects an item from the model and returns that map value.-
Methods inherited from class org.jdesktop.swingx.combobox.ListComboBoxModel
getElementAt, getSelectedItem, setSelectedItem
-
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
-
-
-
-
Method Detail
-
buildIndex
private static <E> java.util.List<E> buildIndex(java.util.Map<E,?> map)
Builds an index for this model. This method ensures that the map is always presented in a consistent order.This method is called by the constructor and the
Listis passed tosuper.- Type Parameters:
E- the type of keys for the map- Parameters:
map- the map to build an index for- Returns:
- a list containing the map keys
-
getSize
public int getSize()
- Specified by:
getSizein interfacejavax.swing.ListModel<K>- Overrides:
getSizein classListComboBoxModel<K>
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent evt)
- Specified by:
actionPerformedin interfacejava.awt.event.ActionListener- Overrides:
actionPerformedin classListComboBoxModel<K>
-
getValue
public V getValue(java.lang.Object selectedItem)
Selects an item from the model and returns that map value.- Parameters:
selectedItem- the item to select- Returns:
- the value for the selected item
-
getValue
public V getValue(int selectedItem)
Selects an item from the model and returns that map value.- Parameters:
selectedItem- selects the item at the specified index in this model- Returns:
- the value for the item at the selected index
-
-