|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.AbstractListModel
javax.swing.DefaultListModel
project35.util.SortableListModel
public class SortableListModel
One shortfall of DefaultListModel is there is no easy way to sort the items. With a Vector you can employ the Collections.sort() convenience method but then you lose update notifications. This is simply a DefaultListModel with a sort function.
| Field Summary |
|---|
| Fields inherited from class javax.swing.AbstractListModel |
|---|
listenerList |
| Constructor Summary | |
|---|---|
SortableListModel()
DefaultListModel has but one constructor. |
|
| Method Summary | |
|---|---|
void |
add(Object obj)
Make add(Object) call addElement(obj) |
void |
remove(Object obj)
Make remove(Object) call |
void |
sort()
Sort the items in the list - logic is: Check if already sorted and if so return Export a Vector, sort, reimport The screen redraw is the slow part here, assuming the list is not vast. |
void |
sort(Comparator comparator)
As per sort() but you may specify a comparator. |
| Methods inherited from class javax.swing.DefaultListModel |
|---|
add, addElement, capacity, clear, contains, copyInto, elementAt, elements, ensureCapacity, firstElement, get, getElementAt, getSize, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElement, removeElementAt, removeRange, set, setElementAt, setSize, size, toArray, toString, trimToSize |
| 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, wait, wait, wait |
| Constructor Detail |
|---|
public SortableListModel()
| Method Detail |
|---|
public void sort()
public void sort(Comparator comparator)
comparator - The comparator to use.public void add(Object obj)
obj - The object to addpublic void remove(Object obj)
obj - The object to remove
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||