public class KeyedComboBoxModel extends Object implements ComboBoxModel
This class is useful in all cases, where the public text differs from the internal view on the data. A separation between presentation data and processing data is a prerequisite for localizing combobox entries. This model does not allow selected elements, which are not in the list of valid elements.
Constructor and Description |
---|
KeyedComboBoxModel()
Creates a new keyed combobox model.
|
KeyedComboBoxModel(Object[] keys,
Object[] values)
Creates a new keyed combobox model for the given keys and values.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Object key,
Object cbitem)
Adds a new entry to the model.
|
void |
addListDataListener(ListDataListener l)
Adds a listener to the list that's notified each time a change to the data
model occurs.
|
void |
clear()
Removes all entries from the model.
|
int |
findElementIndex(Object key)
Tries to find the index of element with the given key.
|
protected void |
fireListDataEvent(ListDataEvent evt)
Notifies all registered list data listener of the given event.
|
Object |
getElementAt(int index)
Returns the value at the specified index.
|
Object |
getKeyAt(int index)
Returns the key from the given index.
|
Object |
getSelectedItem()
Returns the selected item.
|
Object |
getSelectedKey()
Returns the selected data element or null if none is set.
|
int |
getSize()
Returns the length of the list.
|
void |
removeDataElement(Object key)
Removes an entry from the model.
|
void |
removeListDataListener(ListDataListener l)
Removes a listener from the list that's notified each time a change to
the data model occurs.
|
void |
setAllowOtherValue(boolean allowOtherValue) |
void |
setData(Object[] keys,
Object[] values)
Replaces the data in this combobox model.
|
void |
setSelectedItem(Object anItem)
Set the selected item.
|
void |
setSelectedKey(Object anItem)
Defines the selected key.
|
public KeyedComboBoxModel()
public void setData(Object[] keys, Object[] values)
keys
- the keysvalues
- the valuesprotected void fireListDataEvent(ListDataEvent evt)
evt
- the event.public Object getSelectedItem()
getSelectedItem
in interface ComboBoxModel
null
if there is no selectionpublic void setSelectedKey(Object anItem)
anItem
- the new selected item.public void setSelectedItem(Object anItem)
ListDataListener
s that the contents have
changed.setSelectedItem
in interface ComboBoxModel
anItem
- the list object to select or null
to clear the
selectionpublic void setAllowOtherValue(boolean allowOtherValue)
allowOtherValue
- new flag value.public void addListDataListener(ListDataListener l)
addListDataListener
in interface ListModel
l
- the ListDataListener
to be addedpublic Object getElementAt(int index)
getElementAt
in interface ListModel
index
- the requested indexindex
public Object getKeyAt(int index)
index
- the index of the key.public Object getSelectedKey()
public int getSize()
public void removeListDataListener(ListDataListener l)
removeListDataListener
in interface ListModel
l
- the ListDataListener
to be removedpublic int findElementIndex(Object key)
key
- the key for the element to be searched.public void removeDataElement(Object key)
key
- the keypublic void add(Object key, Object cbitem)
key
- the keycbitem
- the display value.public void clear()
Copyright © 2001–2018 JFree.org. All rights reserved.