|
|
|
|
One problem with simple Interface
|
| Method | Description |
|---|---|
|
Adds a listener to the list that's notified each time a change to the data model occurs. |
|
Returns the value at the specified index. |
|
Returns the length of the list. |
|
Removes a listener from the list that's notified each time a change to the data model occurs. |
The ListDataListener interface must
be implemented by any class that wishes to receive indications of changes to
the data in the ListModel. The
other two methods clearly allow one to determine the number of items in the
list, and to obtain the element at a particular index in the list.
Notice that there is still no way to add or remove items using a pure list
model.
AbstractListModelThe abstract class AbstractListModel
implements the ListModel interface, but
only implements support for the ListDataListener
methods. It is the superclass for a number of subclasses, and provides
support for firing ListDataEvents.
DefaultListModelThe concrete class DefaultListModel
extends AbstractListModel, and adds
support for adding and removing items from the list model. It provides a
large number of methods, loosely basing many of them on the Vector
class. The most immediately relevant methods are:
| Method | Description |
|---|---|
|
Adds the specified component to the end of this list. |
|
Returns the element at the specified position in this list. |
|
Returns the number of components in this list. |
|
Removes the element at the specified position in this list. Returns the element that was removed from the list. |
|
Removes all of the elements from this list. The list will be empty after this call returns (unless it throws an exception). |
|
This page was last modified on 02 October, 2007 |