E
-这个模型的元素类型
public class DefaultListModel<E> extends AbstractListModel<E>
java.util.Vector
API,因为它实现了1.1,
java.util.Vector
X版本,没有集合类的支持,并通知
ListDataListener
s发生变化时。目前,它代表一个
Vector
,在以后的版本将会是一个真正的采集的实现。
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为1.4,为所有JavaBeans™长期存储的支持已被添加到java.beans
包。请看XMLEncoder
。
listenerList
Constructor and Description |
---|
DefaultListModel() |
Modifier and Type | Method and Description |
---|---|
void |
add(int index, E element)
在列表中指定的位置上插入指定的元素。
|
void |
addElement(E element)
将指定的组件添加到列表的结尾。
|
int |
capacity()
返回此列表的当前容量。
|
void |
clear()
从这个列表中移除所有的元素。
|
boolean |
contains(Object elem)
测试指定的对象是否是此列表中的一个组件。
|
void |
copyInto(Object[] anArray)
将此列表的组件复制到指定的数组中。
|
E |
elementAt(int index)
返回指定索引处的组件。
|
Enumeration<E> |
elements()
返回此列表的组件的枚举。
|
void |
ensureCapacity(int minCapacity)
增加此列表的容量,如果必要的话,以确保它至少可以容纳由最小容量参数指定的组件数。
|
E |
firstElement()
返回此列表的第一个组件。
|
E |
get(int index)
返回此列表中指定位置的元素。
|
E |
getElementAt(int index)
返回指定索引处的组件。
|
int |
getSize()
返回此列表中的组件的数目。
|
int |
indexOf(Object elem)
对于第一次出现的搜索
elem 。
|
int |
indexOf(Object elem, int index)
为
elem 第一次搜索,开始搜索在
index 。
|
void |
insertElementAt(E element, int index)
插入指定元素在指定的
index 此列表中的组件。
|
boolean |
isEmpty()
测试此列表是否有任何组件。
|
E |
lastElement()
返回列表的最后一个组件。
|
int |
lastIndexOf(Object elem)
返回的
elem 最后出现的指数。
|
int |
lastIndexOf(Object elem, int index)
elem 向后查找,从指定的索引,并返回一个索引,它。
|
E |
remove(int index)
移除此列表中指定位置的元素。
|
void |
removeAllElements()
从这个列表中移除所有组件,并将其大小设置为零。
|
boolean |
removeElement(Object obj)
从这个列表中移除第一个(最低索引)发生的参数。
|
void |
removeElementAt(int index)
在指定的索引中删除组件。
|
void |
removeRange(int fromIndex, int toIndex)
在指定的索引范围内删除组件。
|
E |
set(int index, E element)
用指定元素替换此列表中指定位置的元素。
|
void |
setElementAt(E element, int index)
设置组件在指定的
index 这个列表可以指定元素。
|
void |
setSize(int newSize)
设置此列表的大小。
|
int |
size()
返回此列表中的组件的数目。
|
Object[] |
toArray()
返回包含此列表中所有元素的数组,以正确的顺序。
|
String |
toString()
返回显示并标识该对象属性的字符串。
|
void |
trimToSize()
装饰这个列表是列出的电流容量。
|
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
public int getSize()
此方法与size
,它实现了在1.2 List
集合框架定义的接口。这个方法的存在与setSize
这样size
识别作为一个JavaBean属性。
size()
public E 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
进入这个列表索引
ArrayIndexOutOfBoundsException
-如果
index
阴性或大于此列表的当前大小
get(int)
public void copyInto(Object[] anArray)
IndexOutOfBoundsException
抛出。
anArray
-阵列的组件被复制
Vector.copyInto(Object[])
public void trimToSize()
Vector.trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity
-所需的最小容量
Vector.ensureCapacity(int)
public void setSize(int newSize)
newSize
-这个列表的新尺寸
Vector.setSize(int)
public int capacity()
Vector.capacity()
public int size()
Vector.size()
public boolean isEmpty()
true
当且仅当该列表中没有的组件,即,其大小为零;
false
否则
Vector.isEmpty()
public Enumeration<E> elements()
Vector.elements()
public boolean contains(Object elem)
elem
-对象
true
指定对象是否是此列表中的组件相同
Vector.contains(Object)
public int indexOf(Object elem)
elem
。
elem
-对象
-1
如果未发现目标
Vector.indexOf(Object)
public int indexOf(Object elem, int index)
elem
第一次搜索,开始搜索在
index
。
elem
-所需组件
index
-从开始搜索指数
elem
第一次发生后发现,
index
;返回
-1
如果
elem
列表中没有发现
Vector.indexOf(Object,int)
public int lastIndexOf(Object elem)
elem
最后出现的指数。
elem
-所需组件
elem
指数;返回
-1
如果未发现目标
Vector.lastIndexOf(Object)
public int lastIndexOf(Object elem, int index)
elem
向后查找,从指定的索引,并返回一个索引,它。
elem
-所需组件
index
-开始搜索指数
index
对列表中的
elem
最后出现的指标;返回
-1
如果未发现目标
Vector.lastIndexOf(Object,int)
public E elementAt(int index)
ArrayIndexOutOfBoundsException
如果指数为负或不低于该列表的大小。
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
进入这个列表索引
get(int)
,
Vector.elementAt(int)
public E firstElement()
NoSuchElementException
如果vector不成分。
Vector.firstElement()
public E lastElement()
NoSuchElementException
如果vector不成分。
Vector.lastElement()
public void setElementAt(E element, int index)
index
这个列表可以指定元素。该位置上的前一个组件将被丢弃。
抛出一个ArrayIndexOutOfBoundsException
如果索引无效。
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.
element
什么组件被设置为
index
-指定索引
set(int,Object)
,
Vector.setElementAt(Object,int)
public void removeElementAt(int index)
抛出一个ArrayIndexOutOfBoundsException
如果索引无效。
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
-对象删除索引
remove(int)
,
Vector.removeElementAt(int)
public void insertElementAt(E element, int index)
index
此列表中的组件。
抛出一个ArrayIndexOutOfBoundsException
如果索引无效。
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.
element
-插入元件
index
-如何插入新的组件
ArrayIndexOutOfBoundsException
-如果索引无效
add(int,Object)
,
Vector.insertElementAt(Object,int)
public void addElement(E element)
element
-要添加的组件
Vector.addElement(Object)
public boolean removeElement(Object obj)
obj
-要移除的组件
true
如果参数是这个列表的一个组成部分;
false
否则
Vector.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.
public Object[] toArray()
Vector.toArray()
public E get(int index)
抛出一个ArrayIndexOutOfBoundsException
如果索引超出范围(index < 0 || index >= size()
)。
index
索引元素返回
public E set(int index, E element)
抛出一个ArrayIndexOutOfBoundsException
如果索引超出范围(index < 0 || index >= size()
)。
index
指数要替换的元素
element
元素被存储在指定的位置
public void add(int index, E element)
抛出一个ArrayIndexOutOfBoundsException
如果索引超出范围(index < 0 || index > size()
)。
index
指数在指定的元素被插入
element
元素被插入
public E remove(int index)
抛出一个ArrayIndexOutOfBoundsException
如果索引超出范围(index < 0 || index >= size()
)。
index
-索引的元素删除
public void clear()
public void removeRange(int fromIndex, int toIndex)
抛出一个ArrayIndexOutOfBoundsException
如果索引无效。抛出一个IllegalArgumentException
如果fromIndex > toIndex
。
fromIndex
-范围的下限指标
toIndex
-范围的上限指标
remove(int)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.