public class OptionsListModel<T> extends AbstractList<T> implements ListModel<T>
List
and
ListModel
(which ListModel
really
ought to do itself), and also provides methods to create
some useful models like JComboBoxModel
based on the same data.modCount
Constructor and Description |
---|
OptionsListModel() |
Modifier and Type | Method and Description |
---|---|
boolean |
add(T obj) |
void |
addListDataListener(ListDataListener l) |
void |
fireContentsChanged(int i0,
int i1) |
void |
fireIntervalAdded(int i0,
int i1) |
void |
fireIntervalRemoved(int i0,
int i1) |
T |
get(int index) |
T |
getElementAt(int index) |
int |
getSize() |
int |
idToIndex(int id)
Returns the index at which an option with the given ID currently resides.
|
int |
indexToId(int index)
Returns the unique ID value for the option currently at a given index
in this list.
|
CheckBoxMenu |
makeCheckBoxMenu(String menuName) |
JComboBox<T> |
makeComboBox()
Makes a new JComboBox from this model.
|
ComboBoxModel<T> |
makeComboBoxModel()
Constructs a new ComboBoxModel backed by this list.
|
JMenu |
makeJMenu(String menuName,
Action menuAction)
Constructs a new JMenu backed by this list.
|
T |
remove(int irow) |
void |
removeListDataListener(ListDataListener l) |
T |
set(int irow,
T obj) |
int |
size() |
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
parallelStream, removeIf, stream
public T get(int index)
public T getElementAt(int index)
getElementAt
in interface ListModel<T>
public int size()
size
in interface Collection<T>
size
in interface List<T>
size
in class AbstractCollection<T>
public boolean add(T obj)
add
in interface Collection<T>
add
in interface List<T>
add
in class AbstractList<T>
public T remove(int irow)
public int indexToId(int index)
index
- current index for optionpublic int idToIndex(int id)
id
- unique identifierid
, or -1indexToId(int)
public ComboBoxModel<T> makeComboBoxModel()
makeComboBox()
public JComboBox<T> makeComboBox()
makeComboBoxModel()
by ensuring that the box is
revalidated when new items are added to the model; otherwise the
box can end up too small.
Note however that no renderer is installed, so custom rendering must be as required handled by client code.
public JMenu makeJMenu(String menuName, Action menuAction)
menuAction
action
if selected. In this case the action's actionPerformed
method will be called with an ActionEvent
that has
an id
corresponding to its position in this list and
a command
string which is the same as its toString method.menuName
- the name of the menumenuAction
- the action to activatepublic CheckBoxMenu makeCheckBoxMenu(String menuName)
public void addListDataListener(ListDataListener l)
addListDataListener
in interface ListModel<T>
public void removeListDataListener(ListDataListener l)
removeListDataListener
in interface ListModel<T>
public void fireContentsChanged(int i0, int i1)
public void fireIntervalAdded(int i0, int i1)
public void fireIntervalRemoved(int i0, int i1)
Copyright © 2003-2025 CCLRC: Council for the Central Laboratory of the Research Councils. All Rights Reserved.