java.lang.Object | +--javax.swing.AbstractListModel | +--javax.swing.DefaultListModel
Safe: This class loosely implements the java.util.Vector
API, in that it implements the 1.1.x version of
java.util.Vector
, has no collection class support,
and notifies the ListDataListener
s when changes occur.
Presently it delegates to a Vector
,
in a future release it will be a real Collection implementation.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans
package.
Please see java.beans.XMLEncoder
.
DefaultListModel()
void
add(int index,
Object element)
boolean
contains(Object elem)
void
copyInto(Object[] anArray)
void
ensureCapacity(int minCapacity)
int
indexOf(Object elem,
int index)
elem
, beginning
the search at index
.
void
insertElementAt(Object obj,
int index)
index
.
int
lastIndexOf(Object elem,
int index)
elem
, starting from the
specified index, and returns an index to it.
boolean
removeElement(Object obj)
void
removeRange(int fromIndex,
int toIndex)
Object
set(int index,
Object element)
void
setElementAt(Object obj,
int index)
index
of this
list to be the specified object.
Object[]
toArray()
String
toString()
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
private Vector delegate
public DefaultListModel()
public int getSize()
This method is identical to size
, which implements the
List
interface defined in the 1.2 Collections framework.
This method exists in conjunction with setSize
so that
size
is identifiable as a JavaBean property.
size()
public Object getElementAt(int index)
Note: Although this method is not deprecated, the preferred method to use isget(int)
, which implements theList
interface defined in the 1.2 Collections framework.
index
- an index into this list
get(int)
public void copyInto(Object[] anArray)
IndexOutOfBoundsException
is thrown.
anArray
- the array into which the components get copiedVector.copyInto(Object[])
public void trimToSize()
Vector.trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacityVector.ensureCapacity(int)
public void setSize(int newSize)
newSize
- the new size of this listVector.setSize(int)
public int capacity()
Vector.capacity()
public int size()
Vector.size()
public boolean isEmpty()
true
if and only if this list has
no components, that is, its size is zero;
false
otherwiseVector.isEmpty()
public Enumeration elements()
Vector.elements()
public boolean contains(Object elem)
elem
- an object
true
if the specified object
is the same as a component in this listVector.contains(Object)
public int indexOf(Object elem)
elem
.
elem
- an object
-1
if the object is not foundVector.indexOf(Object)
public int indexOf(Object elem, int index)
elem
, beginning
the search at index
.
elem
- an desired componentindex
- the index from which to begin searching
elem
is found after index
; returns -1
if the elem
is not found in the listVector.indexOf(Object,int)
public int lastIndexOf(Object elem)
elem
.
elem
- the desired component
elem
in the list; returns -1
if the object is not foundVector.lastIndexOf(Object)
public int lastIndexOf(Object elem, int index)
elem
, starting from the
specified index, and returns an index to it.
elem
- the desired componentindex
- the index to start searching from
elem
in this list at position less than index
;
returns -1
if the object is not foundVector.lastIndexOf(Object,int)
public Object elementAt(int index)
ArrayIndexOutOfBoundsException
if the index
is negative or not less than the size of the list.
Note: Although this method is not deprecated, the preferred method to use isget(int)
, which implements theList
interface defined in the 1.2 Collections framework.
index
- an index into this list
get(int)
,
Vector.elementAt(int)
public Object firstElement()
NoSuchElementException
if this
vector has no components.
Vector.firstElement()
public Object lastElement()
NoSuchElementException
if this vector
has no components.
Vector.lastElement()
public void setElementAt(Object obj, int index)
index
of this
list to be the specified object. The previous component at that
position is discarded.
Throws an ArrayIndexOutOfBoundsException
if the index
is invalid.
Note: Although this method is not deprecated, the preferred method to use isset(int,Object)
, which implements theList
interface defined in the 1.2 Collections framework.
obj
- what the component is to be set toindex
- the specified indexset(int,Object)
,
Vector.setElementAt(Object,int)
public void removeElementAt(int index)
Throws an ArrayIndexOutOfBoundsException
if the index
is invalid.
Note: Although this method is not deprecated, the preferred method to use isremove(int)
, which implements theList
interface defined in the 1.2 Collections framework.
index
- the index of the object to removeremove(int)
,
Vector.removeElementAt(int)
public void insertElementAt(Object obj, int index)
index
.
Throws an ArrayIndexOutOfBoundsException
if the index
is invalid.
Note: Although this method is not deprecated, the preferred method to use isadd(int,Object)
, which implements theList
interface defined in the 1.2 Collections framework.
obj
- the component to insertindex
- where to insert the new componentadd(int,Object)
,
Vector.insertElementAt(Object,int)
public void addElement(Object obj)
obj
- the component to be addedVector.addElement(Object)
public boolean removeElement(Object obj)
obj
- the component to be removed
true
if the argument was a component of this
list; false
otherwiseVector.removeElement(Object)
public void removeAllElements()
Note: Although this method is not deprecated, the preferred method to use isclear
, which implements theList
interface defined in the 1.2 Collections framework.
clear()
,
Vector.removeAllElements()
public String toString()
public Object[] toArray()
Vector.toArray()
public Object get(int index)
Throws an ArrayIndexOutOfBoundsException
if the index is out of range
(index < 0 || index >= size()
).
index
- index of element to returnpublic Object set(int index, Object element)
Throws an ArrayIndexOutOfBoundsException
if the index is out of range
(index < 0 || index >= size()
).
index
- index of element to replaceelement
- element to be stored at the specified position
public void add(int index, Object element)
Throws an ArrayIndexOutOfBoundsException
if the
index is out of range
(index < 0 || index > size()
).
index
- index at which the specified element is to be insertedelement
- element to be insertedpublic Object remove(int index)
Throws an ArrayIndexOutOfBoundsException
if the index is out of range
(index < 0 || index >= size()
).
index
- the index of the element to removedpublic void clear()
public void removeRange(int fromIndex, int toIndex)
Throws an ArrayIndexOutOfBoundsException
if the index was invalid.
Throws an IllegalArgumentException
if
fromIndex > toIndex
.
fromIndex
- the index of the lower end of the rangetoIndex
- the index of the upper end of the rangeremove(int)