- java.lang.Object
-
- javax.swing.AbstractListModel<E>
-
- javax.swing.DefaultListModel<E>
-
- 参数类型
-
E- 此模型的元素类型
- 实现的所有接口
-
Serializable,ListModel<E>
public class DefaultListModel<E> extends AbstractListModel<E>
此类松散地实现了java.util.VectorAPI,因为它实现了java.util.Vector版本的java.util.Vector,没有集合类支持,并在发生更改时通知ListDataListener。 目前它代表Vector,在未来的版本中它将是一个真正的Collection实现。警告:此类的序列化对象与以后的Swing版本不兼容。 当前的序列化支持适用于运行相同版本Swing的应用程序之间的短期存储或RMI。 从1.4开始,
java.beans软件包中添加了对所有JavaBeansjava.beans长期存储的支持。 请参阅XMLEncoder。- 从以下版本开始:
- 1.2
- 另请参见:
- Serialized Form
-
-
字段汇总
-
声明的属性在类 javax.swing.AbstractListModel
listenerList
-
-
构造方法摘要
构造方法 构造器 描述 DefaultListModel()
-
方法摘要
所有方法 实例方法 具体的方法 变量和类型 方法 描述 voidadd(int index, E element)将指定元素插入此列表中的指定位置。voidaddAll(int index, Collection<? extends E> c)从指定的索引开始添加集合中存在的所有元素。voidaddAll(Collection<? extends E> c)将集合中存在的所有元素添加到列表中。voidaddElement(E element)将指定的组件添加到此列表的末尾。intcapacity()返回此列表的当前容量。voidclear()从此列表中删除所有元素。booleancontains(Object elem)测试指定的对象是否是此列表中的组件。voidcopyInto(Object[] anArray)将此列表的组件复制到指定的数组中。EelementAt(int index)返回指定索引处的组件。Enumeration<E>elements()返回此列表的组件的枚举。voidensureCapacity(int minCapacity)如有必要,增加此列表的容量,以确保它至少可以容纳由minimum capacity参数指定的组件数。EfirstElement()返回此列表的第一个组件。Eget(int index)返回此列表中指定位置的元素。EgetElementAt(int index)返回指定索引处的组件。intgetSize()返回此列表中的组件数。intindexOf(Object elem)搜索第一次出现的elem。intindexOf(Object elem, int index)搜索的第一次出现elem,开始在搜索index。voidinsertElementAt(E element, int index)将指定的元素作为组件插入到指定的index此列表中。booleanisEmpty()测试此列表是否包含任何组件。ElastElement()返回列表的最后一个组件。intlastIndexOf(Object elem)返回上次出现的索引elem。intlastIndexOf(Object elem, int index)从指定的索引开始向后搜索elem,并返回索引。Eremove(int index)删除此列表中指定位置的元素。voidremoveAllElements()从此列表中删除所有组件并将其大小设置为零。booleanremoveElement(Object obj)从此列表中删除参数的第一个(索引最低)事件。voidremoveElementAt(int index)删除指定索引处的组件。voidremoveRange(int fromIndex, int toIndex)删除指定索引范围内的组件。Eset(int index, E element)用指定的元素替换此列表中指定位置的元素。voidsetElementAt(E element, int index)将此列表的指定index处的组件设置为指定的元素。voidsetSize(int newSize)设置此列表的大小。intsize()返回此列表中的组件数。Object[]toArray()以正确的顺序返回包含此列表中所有元素的数组。StringtoString()返回显示和标识此对象属性的字符串。voidtrimToSize()将此列表的容量调整为列表的当前大小。
-
-
-
方法详细信息
-
getSize
public int getSize()
返回此列表中的组件数。此方法与
size相同,后者实现了1.2 Collections框架中定义的List接口。 此方法与setSize一起存在,以便size可识别为JavaBean属性。- 结果
- 此列表中的组件数
- 另请参见:
-
size()
-
getElementAt
public E getElementAt(int index)
返回指定索引处的组件。Note: Although this method is not deprecated, the preferred method to use is
get(int), which implements theListinterface defined in the 1.2 Collections framework.- 参数
-
index- 此列表的索引 - 结果
- 指定索引处的组件
- 异常
-
ArrayIndexOutOfBoundsException- 如果index为负数或大于此列表的当前大小 - 另请参见:
-
get(int)
-
copyInto
public void copyInto(Object[] anArray)
将此列表的组件复制到指定的数组中。 该数组必须足够大以容纳此列表中的所有对象,否则将引发IndexOutOfBoundsException。- 参数
-
anArray- 组件复制到的数组 - 另请参见:
-
Vector.copyInto(Object[])
-
trimToSize
public void trimToSize()
将此列表的容量调整为列表的当前大小。- 另请参见:
-
Vector.trimToSize()
-
ensureCapacity
public void ensureCapacity(int minCapacity)
如有必要,增加此列表的容量,以确保它至少可以容纳由minimum capacity参数指定的组件数。- 参数
-
minCapacity- 所需的最小容量 - 另请参见:
-
Vector.ensureCapacity(int)
-
setSize
public void setSize(int newSize)
设置此列表的大小。- 参数
-
newSize- 此列表的新大小 - 另请参见:
-
Vector.setSize(int)
-
capacity
public int capacity()
返回此列表的当前容量。- 结果
- 目前的能力
- 另请参见:
-
Vector.capacity()
-
size
public int size()
返回此列表中的组件数。- 结果
- 此列表中的组件数
- 另请参见:
-
Vector.size()
-
isEmpty
public boolean isEmpty()
测试此列表是否包含任何组件。- 结果
-
true当且仅当此列表没有组件时,即其大小为零; 否则为false - 另请参见:
-
Vector.isEmpty()
-
elements
public Enumeration<E> elements()
返回此列表的组件的枚举。- 结果
- 列表的组件的枚举
- 另请参见:
-
Vector.elements()
-
contains
public boolean contains(Object elem)
测试指定的对象是否是此列表中的组件。- 参数
-
elem- 一个对象 - 结果
-
true如果指定的对象与此列表中的组件相同 - 另请参见:
-
Vector.contains(Object)
-
indexOf
public int indexOf(Object elem)
搜索第一次出现的elem。- 参数
-
elem- 一个对象 - 结果
-
此列表中第一次出现参数的索引;
如果找不到该对象,则返回
-1 - 另请参见:
-
Vector.indexOf(Object)
-
indexOf
public int indexOf(Object elem, int index)
搜索的第一次出现elem,开始在搜索index。- 参数
-
elem- 所需的组件 -
index- 从中开始搜索的索引 - 结果
-
其中的第一次出现的索引
elem被后发现index; 返回-1如果elem没有在列表中找到 - 另请参见:
-
Vector.indexOf(Object,int)
-
lastIndexOf
public int lastIndexOf(Object elem)
返回最后一次出现的索引elem。- 参数
-
elem- 所需的组件 - 结果
-
列表中最后一次出现
elem的索引; 如果找不到该对象,则返回elem - 另请参见:
-
Vector.lastIndexOf(Object)
-
lastIndexOf
public int lastIndexOf(Object elem, int index)
从指定的索引开始向后搜索elem,并返回索引。- 参数
-
elem- 所需的组件 -
index- 开始搜索的索引 - 结果
-
此列表中最后一次出现的
elem的指数小于index; 如果找不到该对象,则返回-1 - 另请参见:
-
Vector.lastIndexOf(Object,int)
-
elementAt
public E elementAt(int index)
返回指定索引处的组件。Note: Although this method is not deprecated, the preferred method to use is
get(int), which implements theListinterface defined in the 1.2 Collections framework.- 参数
-
index- 此列表的索引 - 结果
- 指定索引处的组件
- 异常
-
ArrayIndexOutOfBoundsException- 如果索引为负数或不小于列表的大小 - 另请参见:
-
get(int),Vector.elementAt(int)
-
firstElement
public E firstElement()
返回此列表的第一个组件。- 结果
- 这个清单的第一个组成部分
- 异常
-
NoSuchElementException- 如果此向量没有组件 - 另请参见:
-
Vector.firstElement()
-
lastElement
public E lastElement()
返回列表的最后一个组件。- 结果
- 列表的最后一个组成部分
- 异常
-
NoSuchElementException- 如果此向量没有组件 - 另请参见:
-
Vector.lastElement()
-
setElementAt
public void setElementAt(E element, int index)
将此列表的指定index处的组件设置为指定的元素。 该位置的前一个组件将被丢弃。Note: Although this method is not deprecated, the preferred method to use is
set(int,Object), which implements theListinterface defined in the 1.2 Collections framework.- 参数
-
element-element组件设置为什么 -
index- 指定的索引 - 异常
-
ArrayIndexOutOfBoundsException- 如果索引无效 - 另请参见:
-
set(int,Object),Vector.setElementAt(Object,int)
-
removeElementAt
public void removeElementAt(int index)
删除指定索引处的组件。Note: Although this method is not deprecated, the preferred method to use is
remove(int), which implements theListinterface defined in the 1.2 Collections framework.- 参数
-
index- 要删除的对象的索引 - 异常
-
ArrayIndexOutOfBoundsException- 如果索引无效 - 另请参见:
-
remove(int),Vector.removeElementAt(int)
-
insertElementAt
public void insertElementAt(E element, int index)
将指定的元素作为此列表中的组件插入指定的index。Note: Although this method is not deprecated, the preferred method to use is
add(int,Object), which implements theListinterface defined in the 1.2 Collections framework.- 参数
-
element- 要插入的组件 -
index- 插入新组件的位置 - 异常
-
ArrayIndexOutOfBoundsException- 如果索引无效 - 另请参见:
-
add(int,Object),Vector.insertElementAt(Object,int)
-
addElement
public void addElement(E element)
将指定的组件添加到此列表的末尾。- 参数
-
element- 要添加的组件 - 另请参见:
-
Vector.addElement(Object)
-
removeElement
public boolean removeElement(Object obj)
从此列表中删除参数的第一个(索引最低)事件。- 参数
-
obj- 要删除的组件 - 结果
-
true如果参数是此列表的组成部分; 否则为false - 另请参见:
-
Vector.removeElement(Object)
-
removeAllElements
public void removeAllElements()
从此列表中删除所有组件并将其大小设置为零。Note: Although this method is not deprecated, the preferred method to use is
clear, which implements theListinterface defined in the 1.2 Collections framework.- 另请参见:
-
clear(),Vector.removeAllElements()
-
toArray
public Object[] toArray()
以正确的顺序返回包含此列表中所有元素的数组。- 结果
- 包含列表元素的数组
- 另请参见:
-
Vector.toArray()
-
get
public E get(int index)
返回此列表中指定位置的元素。- 参数
-
index- 要返回的元素的索引 - 结果
- 此列表中指定位置的元素
- 异常
-
ArrayIndexOutOfBoundsException- 如果指数超出范围(index < 0 || index >= size())
-
set
public E set(int index, E element)
用指定的元素替换此列表中指定位置的元素。- 参数
-
index- 要替换的元素的索引 -
element- 要存储在指定位置的元素 - 结果
- 先前在指定位置的元素
- 异常
-
ArrayIndexOutOfBoundsException- 如果指数超出范围(index < 0 || index >= size())
-
add
public void add(int index, E element)将指定元素插入此列表中的指定位置。- 参数
-
index- 要插入指定元素的索引 -
element- 要插入的元素 - 异常
-
ArrayIndexOutOfBoundsException- 如果指数超出范围(index < 0 || index > size())
-
remove
public E remove(int index)
删除此列表中指定位置的元素。 返回从列表中删除的元素- 参数
-
index- 要删除的元素的索引 - 结果
- 先前在指定位置的元素
- 异常
-
ArrayIndexOutOfBoundsException- 如果指数超出范围(index < 0 || index >= size())
-
clear
public void clear()
从此列表中删除所有元素。 此调用返回后列表将为空(除非它抛出异常)。
-
removeRange
public void removeRange(int fromIndex, int toIndex)删除指定索引范围内的组件。 删除是包含的,因此指定范围(1,5)将删除索引1处的组件和索引5处的组件,以及其间的所有组件。- 参数
-
fromIndex- 范围下限的索引 -
toIndex- 范围上限的索引 - 异常
-
ArrayIndexOutOfBoundsException- 如果索引无效 -
IllegalArgumentException- 如果是fromIndex > toIndex - 另请参见:
-
remove(int)
-
addAll
public void addAll(Collection<? extends E> c)
将集合中存在的所有元素添加到列表中。- 参数
-
c- 包含要添加的元素的集合 - 异常
-
NullPointerException- 如果c为空
-
addAll
public void addAll(int index, Collection<? extends E> c)从指定的索引开始添加集合中存在的所有元素。- 参数
-
index- 从指定集合插入第一个元素的索引 -
c- 包含要添加的元素的集合 - 异常
-
ArrayIndexOutOfBoundsException- 如果index不在当前持有的元素数量范围内 -
NullPointerException- 如果c为空
-
-