- java.lang.Object
-
- javax.swing.DefaultListSelectionModel
-
- 实现的所有接口
-
Serializable,Cloneable,ListSelectionModel
public class DefaultListSelectionModel extends Object implements ListSelectionModel, Cloneable, Serializable
列表选择的默认数据模型。警告:此类的序列化对象与以后的Swing版本不兼容。 当前的序列化支持适用于运行相同版本Swing的应用程序之间的短期存储或RMI。 从1.4开始,
java.beans软件包中添加了对所有JavaBeansjava.beans长期存储的支持。 请参阅XMLEncoder。- 从以下版本开始:
- 1.2
- 另请参见:
-
ListSelectionModel, Serialized Form
-
-
字段汇总
字段 变量和类型 字段 描述 protected booleanleadAnchorNotificationEnabled是否启用了主要锚点通知。protected EventListenerListlistenerList听众列表。-
Fields declared in interface javax.swing.ListSelectionModel
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION
-
-
构造方法摘要
构造方法 构造器 描述 DefaultListSelectionModel()
-
方法摘要
所有方法 实例方法 具体的方法 变量和类型 方法 描述 voidaddSelectionInterval(int index0, int index1)将选择更改为当前选择的index0并且包括index0和index1之间的索引。Objectclone()返回具有相同选择的此选择模型的副本。protected voidfireValueChanged(boolean isAdjusting)通知听众我们已经结束了一系列调整。protected voidfireValueChanged(int firstIndex, int lastIndex)通知ListSelectionListeners该选择的值,在闭区间firstIndex,lastIndex,已经改变。protected voidfireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)<T extends EventListener>
T[]getListeners(类<T> listenerType)返回此模型上当前注册为FooListener的所有对象的数组。ListSelectionListener[]getListSelectionListeners()返回在此DefaultListSelectionModel上注册的所有列表选择侦听器的数组。voidinsertIndexInterval(int index, int length, boolean before)在索引之前/之后插入长度索引。booleanisLeadAnchorNotificationEnabled()返回leadAnchorNotificationEnabled标志的值。voidmoveLeadSelectionIndex(int leadIndex)设置前导选择索引,保持所有选择值不变。voidremoveIndexInterval(int index0, int index1)从选择模型中删除区间index0,index1(包括)中的索引。voidremoveSelectionInterval(int index0, int index1)将选择更改为当前选择的设置差异以及index0和index1之间的索引。voidsetAnchorSelectionIndex(int anchorIndex)设置锚点选择索引,保持所有选择值不变。voidsetLeadAnchorNotificationEnabled(boolean flag)设置leadAnchorNotificationEnabled标志的值。voidsetLeadSelectionIndex(int leadIndex)设置潜在客户选择索引,确保锚点和新潜在客户之间的值全部被选中或全部取消选择。voidsetSelectionInterval(int index0, int index1)将选择更改为index0和index1含)。voidsetSelectionMode(int selectionMode)设置选择模式。StringtoString()返回显示和标识此对象属性的字符串。-
声明方法的接口 javax.swing.ListSelectionModel
addListSelectionListener, clearSelection, getAnchorSelectionIndex, getLeadSelectionIndex, getMaxSelectionIndex, getMinSelectionIndex, getSelectedIndices, getSelectedItemsCount, getSelectionMode, getValueIsAdjusting, isSelectedIndex, isSelectionEmpty, removeListSelectionListener, setValueIsAdjusting
-
-
-
-
字段详细信息
-
listenerList
protected EventListenerList listenerList
听众列表。
-
leadAnchorNotificationEnabled
protected boolean leadAnchorNotificationEnabled
是否启用了主要锚点通知。
-
-
方法详细信息
-
setSelectionMode
public void setSelectionMode(int selectionMode)
设置选择模式。 以下列表描述了可接受的选择模式:-
ListSelectionModel.SINGLE_SELECTION- 一次只能选择一个列表索引。 在此模式下,setSelectionInterval和addSelectionInterval是等效的,它们都用第二个参数(“lead”)表示的索引替换当前选择。 -
ListSelectionModel.SINGLE_INTERVAL_SELECTION- 一次只能选择一个连续的间隔。 在此模式下,addSelectionInterval行为类似于setSelectionInterval(替换当前选择),除非给定的间隔与现有选择紧邻或重叠,因此可用于增长它。 -
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION- 在此模式下,可以选择的内容没有限制。
- Specified by:
-
setSelectionMode在ListSelectionModel - 参数
-
selectionMode- 选择模式 - 异常
-
IllegalArgumentException- 如果选择模式不是允许的模式之一 - 另请参见:
-
ListSelectionModel.getSelectionMode()
-
-
getListSelectionListeners
public ListSelectionListener[] getListSelectionListeners()
返回在此DefaultListSelectionModel上注册的所有列表选择侦听器的数组。- 结果
-
如果当前没有注册列表选择侦听器,则所有此模型的
ListSelectionListener或空数组 - 从以下版本开始:
- 1.4
- 另请参见:
-
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener),ListSelectionModel.removeListSelectionListener(javax.swing.event.ListSelectionListener)
-
fireValueChanged
protected void fireValueChanged(boolean isAdjusting)
通知听众我们已经结束了一系列调整。- 参数
-
isAdjusting- 如果这是一系列调整的最终更改,isAdjustingtrue
-
fireValueChanged
protected void fireValueChanged(int firstIndex, int lastIndex)通知ListSelectionListeners该选择的值,在闭区间firstIndex,lastIndex,已经改变。- 参数
-
firstIndex- 间隔中的第一个索引 -
lastIndex- 间隔中的最后一个索引
-
fireValueChanged
protected void fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)- 参数
-
firstIndex- 间隔中的第一个索引 -
lastIndex- 间隔中的最后一个索引 -
isAdjusting- 如果这是一系列调整的最终更改,isAdjustingtrue - 另请参见:
-
EventListenerList
-
getListeners
public <T extends EventListener> T[] getListeners(类<T> listenerType)
返回此模型上当前注册为FooListener的所有对象的数组。FooListeners使用addFooListener方法注册。您可以使用类文字指定
listenerType参数,例如FooListener.class。 例如,您可以使用以下代码查询DefaultListSelectionModel实例m以获取其列表选择侦听器:ListSelectionListener[] lsls = (ListSelectionListener[])(m.getListeners(ListSelectionListener.class));如果不存在此类侦听器,则此方法返回空数组。- 参数类型
-
T- 要求的EventListener类的类型 - 参数
-
listenerType- 请求的侦听器类型; 此参数应指定从java.util.EventListener的接口 - 结果
-
此模型上注册为
FooListener的所有对象的数组,如果未添加此类侦听器,则为空数组 - 异常
-
ClassCastException- 如果listenerType未指定实现java.util.EventListener的类或接口 - 从以下版本开始:
- 1.3
- 另请参见:
-
getListSelectionListeners()
-
setLeadAnchorNotificationEnabled
public void setLeadAnchorNotificationEnabled(boolean flag)
设置leadAnchorNotificationEnabled标志的值。- 参数
-
flag-布尔值leadAnchorNotificationEnabled - 另请参见:
-
isLeadAnchorNotificationEnabled()
-
isLeadAnchorNotificationEnabled
public boolean isLeadAnchorNotificationEnabled()
返回leadAnchorNotificationEnabled标志的值。 当leadAnchorNotificationEnabled为真时,模型会生成通知事件,其范围涵盖选择的所有更改以及对潜在客户和锚索引的更改。 将标志设置为false会导致事件边界的缩小,以仅包括自上次更改以来已选择或取消选择的元素。 无论哪种方式,模型都会继续在内部维护主变量和锚点变量。 默认值为true。注意:可以在不更改选择的情况下更改导联或锚点。 通知这些更改通常很重要,例如需要在视图中更新新的潜在客户或锚点时。 因此,在更改默认值时要小心。
- 结果
-
leadAnchorNotificationEnabled标志的值 - 另请参见:
-
setLeadAnchorNotificationEnabled(boolean)
-
setSelectionInterval
public void setSelectionInterval(int index0, int index1)将选择更改为index0和index1含)。index0不必小于或等于index1。在
SINGLE_SELECTION选择模式中,仅使用第二个索引。如果这表示对当前选择的更改,则会通知每个
ListSelectionListener更改。如果任一索引是
-1,则此方法不执行任何操作,并且无异常返回。 否则,如果任一索引小于-1,则抛出IndexOutOfBoundsException。- Specified by:
-
setSelectionInterval,界面ListSelectionModel - 参数
-
index0- 间隔的一端。 -
index1- 间隔的另一端 - 异常
-
IndexOutOfBoundsException- 如果任一索引小于-1(且两个索引都不是-1) - 另请参见:
-
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)
-
addSelectionInterval
public void addSelectionInterval(int index0, int index1)将选择更改为当前选择的集合并且index0和index1之间的索引。在
SINGLE_SELECTION选择模式中,这相当于调用setSelectionInterval,并且仅使用第二个索引。 在SINGLE_INTERVAL_SELECTION选择模式下,此方法的行为类似于setSelectionInterval,除非给定的间隔与现有选择紧邻或重叠,因此可用于增长它。如果这表示对当前选择的更改,则会通知每个
ListSelectionListener更改。 请注意,index0不必小于或等于index1。如果任一索引是
-1,则此方法不执行任何操作,并且无异常返回。 否则,如果任一索引小于-1,则抛出IndexOutOfBoundsException。- Specified by:
-
addSelectionInterval在界面ListSelectionModel - 参数
-
index0- 间隔的一端。 -
index1- 间隔的另一端 - 异常
-
IndexOutOfBoundsException- 如果任一索引小于-1(并且两个索引都不是-1) - 另请参见:
-
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener),setSelectionInterval(int, int)
-
removeSelectionInterval
public void removeSelectionInterval(int index0, int index1)将选择更改为当前选择与index0和index1含)之间的指数的设置差异。index0不必小于或等于index1。在
SINGLE_INTERVAL_SELECTION选择模式中,如果删除将产生两个不相交的选择,则删除将通过选择的较大端进行扩展。 例如,如果选择是0-10并且您提供索引5,6(以任何顺序),则结果选择为0-4。如果这表示对当前选择的更改,则会通知每个
ListSelectionListener更改。如果任一索引是
-1,则此方法不执行任何操作,并且无异常返回。 否则,如果任一索引小于-1,则抛出IndexOutOfBoundsException。- Specified by:
-
removeSelectionInterval,界面ListSelectionModel - 参数
-
index0- 间隔的一端 -
index1- 间隔的另一端 - 异常
-
IndexOutOfBoundsException- 如果任一索引小于-1(并且两个索引都不是-1) - 另请参见:
-
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)
-
insertIndexInterval
public void insertIndexInterval(int index, int length, boolean before)在索引之前/之后插入长度索引。 如果索引处的值本身已选中且选择模式不是SINGLE_SELECTION,请将所有新插入的项目设置为选中。 否则将他们取消选中。 通常调用此方法以使选择模型与数据模型中的相应变化同步。- Specified by:
-
insertIndexInterval在ListSelectionModel - 参数
-
index- 间隔的开始 -
length- 间隔的长度 -
before- 如果true,间隔在index之前插入,否则,间隔在index之后插入
-
removeIndexInterval
public void removeIndexInterval(int index0, int index1)从选择模型中删除区间index0,index1(包括)中的索引。 这通常被称为使选择模型宽度与数据模型中的相应变化同步。 注意(一如既往)index0不必是<= index1。- Specified by:
-
removeIndexInterval,界面ListSelectionModel - 参数
-
index0- 间隔的开始 -
index1- 间隔结束
-
clone
public Object clone() throws CloneNotSupportedException
返回具有相同选择的此选择模型的副本。listenerLists不重复。- 重写:
-
clone,类Object - 结果
- 这个实例的克隆。
- 异常
-
CloneNotSupportedException- 如果选择模型不同时(a)实现Cloneable接口和(b)定义clone方法。 - 另请参见:
-
Cloneable
-
setAnchorSelectionIndex
public void setAnchorSelectionIndex(int anchorIndex)
设置锚点选择索引,保持所有选择值不变。 如果leadAnchorNotificationEnabled为true,则发送覆盖旧锚单元和新锚单元的通知。- Specified by:
-
setAnchorSelectionIndex,界面ListSelectionModel - 参数
-
anchorIndex- 锚选择索引 - 另请参见:
-
ListSelectionModel.getAnchorSelectionIndex(),setLeadSelectionIndex(int)
-
moveLeadSelectionIndex
public void moveLeadSelectionIndex(int leadIndex)
设置前导选择索引,保持所有选择值不变。 如果leadAnchorNotificationEnabled为true,则发送覆盖旧的和新的潜在客户单元的通知。- 参数
-
leadIndex- 新的潜在客户选择指数 - 从以下版本开始:
- 1.5
- 另请参见:
-
setAnchorSelectionIndex(int),setLeadSelectionIndex(int),ListSelectionModel.getLeadSelectionIndex()
-
setLeadSelectionIndex
public void setLeadSelectionIndex(int leadIndex)
设置潜在客户选择索引,确保锚点和新潜在客户之间的值全部被选中或全部取消选择。 如果选择锚索引处的值,首先清除[anchor,oldLeadIndex]范围内的所有值,然后选择[anchor,newLeadIndex]范围内的所有值值,其中oldLeadIndex是旧的leadIndex,newLeadIndex是新的一。如果未选择锚索引处的值,则在反向选择旧范围中的值并取消选择新值中的值时执行相同操作。
为此更改生成单个事件并通知所有侦听器。 为了在此事件中生成最小边界,请在单个过程中执行操作; 这样,广播的ListSelectionEvent中的第一个和最后一个索引将引用由于此方法而实际更改值的单元格。 相反,如果此操作分两步完成,则对选择状态的影响将相同,但会生成两个事件,并且更改值周围的边界将更宽,包括先被清除但后来才被设置的单元格。
此方法可用于UI类的
mouseDragged方法以扩展选择。- Specified by:
-
setLeadSelectionIndex在接口ListSelectionModel - 参数
-
leadIndex- 潜在客户选择指数 - 另请参见:
-
ListSelectionModel.getLeadSelectionIndex(),setAnchorSelectionIndex(int)
-
-