- 所有已实现的接口:
Serializable,Cloneable,ListSelectionModel
Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder 。
- 自从:
- 1.2
- 参见:
-
字段摘要
字段在接口 javax.swing.ListSelectionModel 中声明的字段
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION -
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述void将一个监听添加到列表中,每次发生选择更改时都会通知该列表。voidaddSelectionInterval(int index0, int index1) 将选择更改为当前选择的集合并集以及index0和index1之间的索引(含)。void将选择更改为空集。clone()返回具有相同选择的此选择模型的克隆。protected voidfireValueChanged(boolean isAdjusting) 通知听众我们已经结束了一系列调整。protected voidfireValueChanged(int firstIndex, int lastIndex) 通知ListSelectionListeners在闭区间firstIndex、lastIndex中选择的值已更改。protected voidfireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting) 通知ListSelectionListeners在闭区间firstIndex和lastIndex中选择的值已经改变,如果这是一系列调整中的最后一个改变。int返回最近调用 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的第一个索引参数。int返回最近调用 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的第二个索引参数。<T extends EventListener>
T[]getListeners(Class<T> listenerType) 返回当前在此模型上注册为FooListener的所有对象的数组。返回在此DefaultListSelectionModel上注册的所有列表选择监听器的数组。int如果选择为空,则返回最后选择的索引或 -1。int返回第一个选定的索引,如果选择为空,则返回 -1。int返回当前选择模式。boolean如果选择正在进行一系列更改,则返回true。voidinsertIndexInterval(int index, int length, boolean before) 在索引之前/之后插入长度索引。boolean返回leadAnchorNotificationEnabled标志的值。booleanisSelectedIndex(int index) 如果选择了指定的索引,则返回 true。boolean如果没有选择索引,则返回 true。voidmoveLeadSelectionIndex(int leadIndex) 设置引导选择索引,保持所有选择值不变。voidremoveIndexInterval(int index0, int index1) 从选择模型中删除区间 index0,index1(含)中的索引。void从每次发生选择更改时通知的列表中删除一个监听。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) 设置选择模式。voidsetValueIsAdjusting(boolean isAdjusting) 设置valueIsAdjusting属性,指示即将发生的选择更改是否应被视为单个更改的一部分。toString()返回显示和标识此对象属性的字符串。在接口 javax.swing.ListSelectionModel 中声明的方法
getSelectedIndices, getSelectedItemsCount
-
字段详细信息
-
listenerList
听众名单。 -
leadAnchorNotificationEnabled
protected boolean leadAnchorNotificationEnabled是否启用主锚通知。
-
-
构造方法详细信息
-
DefaultListSelectionModel
public DefaultListSelectionModel()构造一个DefaultListSelectionModel
-
-
方法详情
-
getMinSelectionIndex
public int getMinSelectionIndex()返回第一个选定的索引,如果选择为空,则返回 -1。- 指定者:
getMinSelectionIndex在接口ListSelectionModel中- 返回:
- 第一个选择的索引或 -1 如果选择为空。
-
getMaxSelectionIndex
public int getMaxSelectionIndex()如果选择为空,则返回最后选择的索引或 -1。- 指定者:
getMaxSelectionIndex在接口ListSelectionModel中- 返回:
- 最后选择的索引或 -1 如果选择为空。
-
getValueIsAdjusting
public boolean getValueIsAdjusting()如果选择正在进行一系列更改,则返回true。- 指定者:
getValueIsAdjusting在接口ListSelectionModel中- 返回:
- 如果选择正在进行一系列更改,则为真
- 参见:
-
getSelectionMode
public int getSelectionMode()返回当前选择模式。- 指定者:
getSelectionMode在接口ListSelectionModel中- 返回:
- 当前选择模式
- 参见:
-
setSelectionMode
public void setSelectionMode(int selectionMode) 设置选择模式。以下列表描述了可接受的选择模式:ListSelectionModel.SINGLE_SELECTION- 一次只能选择一个列表索引。在这种模式下,setSelectionInterval和addSelectionInterval是等效的,都用第二个参数(“lead”)表示的索引替换当前选择。ListSelectionModel.SINGLE_INTERVAL_SELECTION- 一次只能选择一个连续的间隔。在这种模式下,addSelectionInterval的行为类似于setSelectionInterval(替换当前选择),除非给定间隔与现有选择紧邻或重叠,因此可用于增长它。ListSelectionModel.MULTIPLE_INTERVAL_SELECTION- 在此模式下,可以选择的内容没有限制。
- 指定者:
setSelectionMode在接口ListSelectionModel中- 参数:
selectionMode- 选择模式- 抛出:
IllegalArgumentException- 如果选择模式不是允许的模式之一- 参见:
-
isSelectedIndex
public boolean isSelectedIndex(int index) 如果选择了指定的索引,则返回 true。- 指定者:
isSelectedIndex在接口ListSelectionModel中- 参数:
index- 索引- 返回:
true如果指定索引被选中
-
isSelectionEmpty
public boolean isSelectionEmpty()如果没有选择索引,则返回 true。- 指定者:
isSelectionEmpty在接口ListSelectionModel中- 返回:
true如果没有选择索引。
-
addListSelectionListener
将一个监听添加到列表中,每次发生选择更改时都会通知该列表。- 指定者:
addListSelectionListener在接口ListSelectionModel中- 参数:
l- ListSelectionListener- 参见:
-
removeListSelectionListener
从每次发生选择更改时通知的列表中删除一个监听。- 指定者:
removeListSelectionListener在接口ListSelectionModel中- 参数:
l- ListSelectionListener- 参见:
-
getListSelectionListeners
返回在此DefaultListSelectionModel上注册的所有列表选择监听器的数组。- 返回:
-
此模型的所有
ListSelectionListeners 或空数组(如果当前未注册列表选择监听器) - 自从:
- 1.4
- 参见:
-
fireValueChanged
protected void fireValueChanged(boolean isAdjusting) 通知听众我们已经结束了一系列调整。- 参数:
isAdjusting- 如果这是一系列调整中的最后一个更改,则为真
-
fireValueChanged
protected void fireValueChanged(int firstIndex, int lastIndex) 通知ListSelectionListeners在闭区间firstIndex、lastIndex中选择的值已更改。- 参数:
firstIndex- 区间中的第一个索引lastIndex- 间隔中的最后一个索引
-
fireValueChanged
protected void fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting) 通知ListSelectionListeners在闭区间firstIndex和lastIndex中选择的值已经改变,如果这是一系列调整中的最后一个改变。- 参数:
firstIndex- 区间中的第一个索引lastIndex- 间隔中的最后一个索引isAdjusting- 如果这是一系列调整中的最后一个更改,则为真- 参见:
-
getListeners
返回当前在此模型上注册为FooListener的所有对象的数组。FooListener是使用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
- 参见:
-
setLeadAnchorNotificationEnabled
public void setLeadAnchorNotificationEnabled(boolean flag) 设置 leadAnchorNotificationEnabled 标志的值。- 参数:
flag-leadAnchorNotificationEnabled的boolean- 参见:
-
isLeadAnchorNotificationEnabled
public boolean isLeadAnchorNotificationEnabled()返回leadAnchorNotificationEnabled标志的值。当leadAnchorNotificationEnabled为真时,模型会生成通知事件,其范围涵盖对选择的所有更改以及对引导和锚索引的更改。将标志设置为 false 会导致事件范围缩小,仅包括自上次更改以来已选择或取消选择的元素。无论哪种方式,模型都会继续在内部维护引导变量和锚定变量。默认为真。注意:可以在不更改选择的情况下更改引导或锚点。这些更改的通知通常很重要,例如何时需要在视图中更新新的线索或锚点。因此,更改默认值时应谨慎。
- 返回:
leadAnchorNotificationEnabled标志的值- 参见:
-
clearSelection
public void clearSelection()将选择更改为空集。如果这表示对当前选择的更改,则通知每个 ListSelectionListener。- 指定者:
clearSelection在接口ListSelectionModel中- 参见:
-
setSelectionInterval
public void setSelectionInterval(int index0, int index1) 将选择更改为介于index0和index1之间(含)。index0不必小于或等于index1。在
SINGLE_SELECTION选择模式下,只使用第二个索引。如果这表示对当前选择的更改,则每个
ListSelectionListener都会收到更改通知。如果任一索引为
-1,则此方法不执行任何操作并无一例外地返回。否则,如果任一索引小于-1,则抛出IndexOutOfBoundsException。- 指定者:
setSelectionInterval在接口ListSelectionModel中- 参数:
index0- 区间的一端。index1- 区间的另一端- 抛出:
IndexOutOfBoundsException- 如果任一索引小于-1(并且两个索引都不是-1)- 参见:
-
addSelectionInterval
public void addSelectionInterval(int index0, int index1) 将选择更改为当前选择的集合并集以及index0和index1之间的索引(含)。在
SINGLE_SELECTION选择模式下,这相当于调用setSelectionInterval,只使用第二个索引。在SINGLE_INTERVAL_SELECTION选择模式下,此方法的行为类似于setSelectionInterval,除非给定间隔与现有选择紧邻或重叠,因此可用于增长它。如果这表示对当前选择的更改,则每个
ListSelectionListener都会收到更改通知。请注意,index0不必小于或等于index1。如果任一索引为
-1,则此方法不执行任何操作并无一例外地返回。否则,如果任一索引小于-1,则抛出IndexOutOfBoundsException。- 指定者:
addSelectionInterval在接口ListSelectionModel中- 参数:
index0- 区间的一端。index1- 区间的另一端- 抛出:
IndexOutOfBoundsException- 如果任一索引小于-1(并且两个索引都不是-1)- 参见:
-
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。- 指定者:
removeSelectionInterval在接口ListSelectionModel中- 参数:
index0- 区间的一端index1- 区间的另一端- 抛出:
IndexOutOfBoundsException- 如果任一索引小于-1(并且两个索引都不是-1)- 参见:
-
insertIndexInterval
public void insertIndexInterval(int index, int length, boolean before) 在索引之前/之后插入长度索引。如果 index 处的值本身被选中并且选择模式不是 SINGLE_SELECTION,则将所有新插入的项目设置为选中。否则不要选择它们。通常调用此方法以将选择模型与数据模型中的相应更改同步。- 指定者:
insertIndexInterval在接口ListSelectionModel中- 参数:
index- 间隔的开始length- 间隔的长度before- 如果是true,则在index之前插入间隔,否则,在index之后插入间隔
-
removeIndexInterval
public void removeIndexInterval(int index0, int index1) 从选择模型中删除区间 index0,index1(含)中的索引。这通常被调用以将选择模型宽度与数据模型中的相应更改同步。请注意(一如既往)index0 不必 <= index1。- 指定者:
removeIndexInterval在接口ListSelectionModel中- 参数:
index0- 间隔的开始index1- 区间结束
-
setValueIsAdjusting
public void setValueIsAdjusting(boolean isAdjusting) 设置valueIsAdjusting属性,指示即将发生的选择更改是否应被视为单个更改的一部分。此属性的值用于初始化生成的ListSelectionEvent的valueIsAdjusting属性。例如,如果选择正在更新以响应用户拖动,则可以在拖动开始时将此属性设置为
true,在拖动完成时设置为false。在拖动期间,监听器会收到valueIsAdjusting属性设置为true的事件。在拖动结束时,当更改完成时,监听器会收到一个值设置为false的事件。如果监听器希望仅在更改完成后才更新,则可以使用此模式。将此属性设置为
true开始一系列更改,这些更改被视为单个更改的一部分。当属性改回false时,将发送一个事件来表征整个选择更改(如果有的话),并将事件的valueIsAdjusting属性设置为false。- 指定者:
setValueIsAdjusting在接口ListSelectionModel中- 参数:
isAdjusting- 属性的新值- 参见:
-
toString
返回显示和标识此对象属性的字符串。 -
clone
返回具有相同选择的此选择模型的克隆。listenerLists不重复。- 重写:
clone在类Object中- 返回:
- 此实例的克隆。
- 抛出:
CloneNotSupportedException- 如果选择模型没有同时 (a) 实现 Cloneable 接口和 (b) 定义clone方法。- 参见:
-
getAnchorSelectionIndex
public int getAnchorSelectionIndex()返回最近调用 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的第一个索引参数。最近的 index0 被认为是“锚”,最近的 index1 被认为是“领先”。有些界面专门显示这些索引,例如Windows95 以黄色虚线轮廓显示引导索引。- 指定者:
getAnchorSelectionIndex在接口ListSelectionModel中- 返回:
- 锚选择指数
- 参见:
-
getLeadSelectionIndex
public int getLeadSelectionIndex()返回最近调用 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的第二个索引参数。- 指定者:
getLeadSelectionIndex在接口ListSelectionModel中- 返回:
- 铅选择指数。
- 参见:
-
setAnchorSelectionIndex
public void setAnchorSelectionIndex(int anchorIndex) 设置锚选择索引,保持所有选择值不变。如果 leadAnchorNotificationEnabled 为真,则发送重写新旧锚点的通知。- 指定者:
setAnchorSelectionIndex在接口ListSelectionModel中- 参数:
anchorIndex- 锚点选择索引- 参见:
-
moveLeadSelectionIndex
public void moveLeadSelectionIndex(int leadIndex) 设置主导选择索引,保持所有选择值不变。如果leadAnchorNotificationEnabled为true,则发送一条通知,涵盖旧的和新的主导单元格.- 参数:
leadIndex- 新的引导选择索引- 自从:
- 1.5
- 参见:
-
setLeadSelectionIndex
public void setLeadSelectionIndex(int leadIndex) 设置潜在客户选择索引,确保锚点和新潜在客户之间的值全部选中或全部取消选择。如果选择了anchor index处的值,首先清空[anchor, oldLeadIndex]范围内的所有值,然后选择[anchor, newLeadIndex]范围内的所有值,其中oldLeadIndex为旧leadIndex,newLeadIndex为新leadIndex .如果未选择锚索引处的值,则反向选择旧范围中的值并取消选择新范围中的值。
为此更改生成单个事件并通知所有监听。为了在此事件中生成最小边界,请一次性完成操作;这样,广播的 ListSelectionEvent 中的第一个和最后一个索引将引用由于此方法而实际更改值的单元格。相反,如果此操作分两步完成,则对选择状态的影响将相同,但会生成两个事件,并且更改值周围的范围会更宽,包括先清除后才设置的单元格.
此方法可用于 UI 类的
mouseDragged方法以扩展选择。- 指定者:
setLeadSelectionIndex在接口ListSelectionModel中- 参数:
leadIndex- 引导选择索引- 参见:
-