public class javax.swing
DefaultListModel


Show All Login
Java SE 6
  
Extends: AbstractListModel
Details
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 ListDataListeners 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.
version1.36 11/17/05


Constructors
public DefaultListModel()

Methods
public void add(int index, Object element) Details
Inserts the specified element at the specified position in this list.

Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index > size()).
indexindex at which the specified element is to be inserted
elementelement to be inserted

public void addElement(Object obj) Details
Adds the specified component to the end of this list.
objthe component to be added
See also addElement(Object)
public int capacity() Details
Returns the current capacity of this list.
returnthe current capacity
See also capacity()
public void clear()
Removes all of the elements from this list. The list will be empty after this call returns (unless it throws an exception).
public boolean contains(Object elem) Details
Tests whether the specified object is a component in this list.
eleman object
returntrue if the specified object is the same as a component in this list
See also contains(Object)
public void copyInto(Object[] anArray) Details
Copies the components of this list into the specified array. The array must be big enough to hold all the objects in this list, else an IndexOutOfBoundsException is thrown.
anArraythe array into which the components get copied
See also copyInto(Object[])
public Object elementAt(int index) Details
Returns the component at the specified index. Throws an 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 is get(int), which implements the List interface defined in the 1.2 Collections framework.
indexan index into this list
returnthe component at the specified index
See also get(int), elementAt(int)
public Enumeration elements() Details
Returns an enumeration of the components of this list.
returnan enumeration of the components of this list
See also elements()
public void ensureCapacity(int minCapacity) Details
Increases the capacity of this list, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
minCapacitythe desired minimum capacity
See also ensureCapacity(int)
public Object firstElement() Details
Returns the first component of this list. Throws a NoSuchElementException if this vector has no components.
returnthe first component of this list
See also firstElement()
public Object get(int index) Details
Returns the element at the specified position in this list.

Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).
indexindex of element to return

public int indexOf(Object elem) Details
Searches for the first occurrence of elem.
eleman object
returnthe index of the first occurrence of the argument in this list; returns -1 if the object is not found
See also indexOf(Object)
public int indexOf(Object elem, int index) Details
Searches for the first occurrence of elem, beginning the search at index.
eleman desired component
indexthe index from which to begin searching
returnthe index where the first occurrence of elem is found after index; returns -1 if the elem is not found in the list
See also indexOf(Object,int)
public void insertElementAt(Object obj, int index) Details
Inserts the specified object as a component in this list at the specified index.

Throws an ArrayIndexOutOfBoundsException if the index is invalid.

Note: Although this method is not deprecated, the preferred method to use is add(int,Object), which implements the List interface defined in the 1.2 Collections framework.
objthe component to insert
indexwhere to insert the new component
ThrowsArrayIndexOutOfBoundsException: if the index was invalid
See also add(int,Object), insertElementAt(Object,int)
public Object lastElement() Details
Returns the last component of the list. Throws a NoSuchElementException if this vector has no components.
returnthe last component of the list
See also lastElement()
public int lastIndexOf(Object elem) Details
Returns the index of the last occurrence of elem.
elemthe desired component
returnthe index of the last occurrence of elem in the list; returns -1 if the object is not found
See also lastIndexOf(Object)
public int lastIndexOf(Object elem, int index) Details
Searches backwards for elem, starting from the specified index, and returns an index to it.
elemthe desired component
indexthe index to start searching from
returnthe index of the last occurrence of the elem in this list at position less than index; returns -1 if the object is not found
See also lastIndexOf(Object,int)
public Object remove(int index) Details
Removes the element at the specified position in this list. Returns the element that was removed from the list.

Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).
indexthe index of the element to removed

public void removeAllElements() Details
Removes all components from this list and sets its size to zero.
Note: Although this method is not deprecated, the preferred method to use is clear, which implements the List interface defined in the 1.2 Collections framework.
See also clear(), removeAllElements()
public boolean removeElement(Object obj) Details
Removes the first (lowest-indexed) occurrence of the argument from this list.
objthe component to be removed
returntrue if the argument was a component of this list; false otherwise
See also removeElement(Object)
public void removeElementAt(int index) Details
Deletes the component at the specified index.

Throws an ArrayIndexOutOfBoundsException if the index is invalid.

Note: Although this method is not deprecated, the preferred method to use is remove(int), which implements the List interface defined in the 1.2 Collections framework.
indexthe index of the object to remove
See also remove(int), removeElementAt(int)
public void removeRange(int fromIndex, int toIndex) Details
Deletes the components at the specified range of indexes. The removal is inclusive, so specifying a range of (1,5) removes the component at index 1 and the component at index 5, as well as all components in between.

Throws an ArrayIndexOutOfBoundsException if the index was invalid. Throws an IllegalArgumentException if fromIndex > toIndex.
fromIndexthe index of the lower end of the range
toIndexthe index of the upper end of the range
See also remove(int)

public Object set(int index, Object element) Details
Replaces the element at the specified position in this list with the specified element.

Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).
indexindex of element to replace
elementelement to be stored at the specified position
returnthe element previously at the specified position

public int size() Details
Returns the number of components in this list.
returnthe number of components in this list
See also size()
public Object[] toArray() Details
Returns an array containing all of the elements in this list in the correct order.
returnan array containing the elements of the list
See also toArray()
public String toString() Details
Returns a string that displays and identifies this object's properties.
returna String representation of this object
public void trimToSize() Details
Trims the capacity of this list to be the list's current size.
See also trimToSize()

Properties
public void setElementAt(Object obj, int index) Details
Sets the component at the specified 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 is set(int,Object), which implements the List interface defined in the 1.2 Collections framework.
objwhat the component is to be set to
indexthe specified index
See also set(int,Object), setElementAt(Object,int)
public Object getElementAt(int index) Details
Returns the component at the specified index.
Note: Although this method is not deprecated, the preferred method to use is get(int), which implements the List interface defined in the 1.2 Collections framework.
indexan index into this list
returnthe component at the specified index
ThrowsArrayIndexOutOfBoundsException: if the index is negative or greater than the current size of this list
See also get(int)
public boolean isEmpty() Details
Tests whether this list has any components.
returntrue if and only if this list has no components, that is, its size is zero; false otherwise
See also isEmpty()
public void setSize(int newSize) Details
Sets the size of this list.
newSizethe new size of this list
See also setSize(int)
public int getSize() Details
Returns the number of components in this list.

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.
returnthe number of components in this list
See also size()