- 所有已知的实现类:
DefaultListSelectionModel
public interface ListSelectionModel
此界面表示显示具有稳定索引的值列表的任何组件的当前选择状态。选择被建模为一组间隔,每个间隔代表选定列表元素的连续范围。修改所选区间集的方法都采用一对索引,index0和index1,它们代表一个闭区间,即区间包括index0和index1。
- 自从:
- 1.2
- 参见:
-
字段摘要
字段修饰符和类型Field描述static final intselectionMode 属性的值:一次选择一个或多个连续的索引范围。static final intselectionMode 属性的值:一次选择一个连续的索引范围。static final intselectionMode 属性的值:一次选择一个列表索引。 -
方法总结
修饰符和类型方法描述void将一个监听添加到列表中,每次发生选择更改时都会通知该列表。voidaddSelectionInterval(int index0, int index1) 将选择更改为当前选择的集合并集以及index0和index1之间的索引(含)。void将选择更改为空集。int返回最近调用 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的第一个索引参数。int返回最近调用 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的第二个索引参数。int如果选择为空,则返回最后选择的索引或 -1。int返回第一个选定的索引,如果选择为空,则返回 -1。default int[]按递增顺序返回选择模型中所有选定索引的数组。default int返回所选项目的数量。int返回当前选择模式。boolean如果选择正在进行一系列更改,则返回true。voidinsertIndexInterval(int index, int length, boolean before) 在index之前/之后插入length索引。booleanisSelectedIndex(int index) 如果选择了指定的索引,则返回 true。boolean如果没有选择索引,则返回 true。voidremoveIndexInterval(int index0, int index1) 从选择模型中删除区间index0,index1(含)中的索引。void从每次发生选择更改时通知的列表中删除一个监听。voidremoveSelectionInterval(int index0, int index1) 将选择更改为当前选择的集合差异以及index0和index1之间的索引(含)。voidsetAnchorSelectionIndex(int index) 设置锚点选择索引。voidsetLeadSelectionIndex(int index) 设置导联选择指数。voidsetSelectionInterval(int index0, int index1) 将选择更改为介于index0和index1之间(含)。voidsetSelectionMode(int selectionMode) 设置选择模式。voidsetValueIsAdjusting(boolean valueIsAdjusting) 设置valueIsAdjusting属性,指示即将发生的选择更改是否应被视为单个更改的一部分。
-
字段详细信息
-
SINGLE_SELECTION
static final int SINGLE_SELECTIONselectionMode 属性的值:一次选择一个列表索引。- 参见:
-
SINGLE_INTERVAL_SELECTION
static final int SINGLE_INTERVAL_SELECTIONselectionMode 属性的值:一次选择一个连续的索引范围。- 参见:
-
MULTIPLE_INTERVAL_SELECTION
static final int MULTIPLE_INTERVAL_SELECTIONselectionMode 属性的值:一次选择一个或多个连续的索引范围。- 参见:
-
-
方法详情
-
setSelectionInterval
void setSelectionInterval(int index0, int index1) 将选择更改为介于index0和index1之间(含)。index0不必小于或等于index1。在
SINGLE_SELECTION选择模式下,只使用第二个索引。如果这表示对当前选择的更改,则每个
ListSelectionListener都会收到更改通知。- 参数:
index0- 区间的一端。index1- 区间的另一端- 参见:
-
addSelectionInterval
void addSelectionInterval(int index0, int index1) 将选择更改为当前选择的集合并集以及index0和index1之间的索引(含)。index0不必小于或等于index1。在
SINGLE_SELECTION选择模式下,这相当于调用setSelectionInterval,只使用第二个索引。在SINGLE_INTERVAL_SELECTION选择模式下,此方法的行为类似于setSelectionInterval,除非给定间隔与现有选择直接相邻或重叠,因此可用于增加选择。如果这表示对当前选择的更改,则每个
ListSelectionListener都会收到更改通知。- 参数:
index0- 区间的一端。index1- 区间的另一端- 参见:
-
removeSelectionInterval
void removeSelectionInterval(int index0, int index1) 将选择更改为当前选择的集合差异以及index0和index1之间的索引(含)。index0不必小于或等于index1。在
SINGLE_INTERVAL_SELECTION选择模式中,如果删除会产生两个不相交的选择,则删除会扩展到选择的较大端。例如,如果选择是0-10并且您提供索引5,6(以任何顺序),则结果选择是0-4。如果这表示对当前选择的更改,则每个
ListSelectionListener都会收到更改通知。- 参数:
index0- 区间的一端。index1- 区间的另一端- 参见:
-
getMinSelectionIndex
int getMinSelectionIndex()返回第一个选定的索引,如果选择为空,则返回 -1。- 返回:
- 第一个选择的索引或 -1 如果选择为空。
-
getMaxSelectionIndex
int getMaxSelectionIndex()如果选择为空,则返回最后选择的索引或 -1。- 返回:
- 最后选择的索引或 -1 如果选择为空。
-
isSelectedIndex
boolean isSelectedIndex(int index) 如果选择了指定的索引,则返回 true。- 参数:
index- 索引- 返回:
true如果指定索引被选中
-
getAnchorSelectionIndex
int getAnchorSelectionIndex()返回最近调用 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的第一个索引参数。最近的 index0 被认为是“锚”,最近的 index1 被认为是“领先”。有些界面专门显示这些索引,例如Windows95 以黄色虚线轮廓显示引导索引。- 返回:
- 锚选择指数
- 参见:
-
setAnchorSelectionIndex
void setAnchorSelectionIndex(int index) 设置锚点选择索引。- 参数:
index- 锚点选择索引- 参见:
-
getLeadSelectionIndex
int getLeadSelectionIndex()返回最近调用 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的第二个索引参数。- 返回:
- 铅选择指数。
- 参见:
-
setLeadSelectionIndex
void setLeadSelectionIndex(int index) 设置导联选择指数。- 参数:
index- 铅选择指数- 参见:
-
clearSelection
void clearSelection()将选择更改为空集。如果这表示对当前选择的更改,则通知每个 ListSelectionListener。- 参见:
-
isSelectionEmpty
boolean isSelectionEmpty()如果没有选择索引,则返回 true。- 返回:
true如果没有选择索引。
-
insertIndexInterval
void insertIndexInterval(int index, int length, boolean before) 在index之前/之后插入length索引。这通常被调用以将选择模型与数据模型中的相应更改同步。- 参数:
index- 间隔的开始length- 间隔的长度before- 如果是true,则在index之前插入间隔,否则,在index之后插入间隔
-
removeIndexInterval
void removeIndexInterval(int index0, int index1) 从选择模型中删除区间index0,index1(含)中的索引。这通常被调用以将选择模型宽度与数据模型中的相应更改同步。- 参数:
index0- 间隔的开始index1- 区间结束
-
setValueIsAdjusting
void setValueIsAdjusting(boolean valueIsAdjusting) 设置valueIsAdjusting属性,指示即将发生的选择更改是否应被视为单个更改的一部分。此属性的值用于初始化生成的ListSelectionEvent的valueIsAdjusting属性。例如,如果选择正在更新以响应用户拖动,则可以在拖动开始时将此属性设置为
true,在拖动完成时设置为false。在拖动期间,监听器会收到valueIsAdjusting属性设置为true的事件。在拖动结束时,当更改完成时,监听器会收到一个值设置为false的事件。如果监听器希望仅在更改完成后才更新,则可以使用此模式。将此属性设置为
true开始一系列更改,这些更改被视为单个更改的一部分。当属性改回false时,将发送一个事件来表征整个选择更改(如果有的话),并将事件的valueIsAdjusting属性设置为false。- 参数:
valueIsAdjusting- 属性的新值- 参见:
-
getValueIsAdjusting
boolean getValueIsAdjusting()如果选择正在进行一系列更改,则返回true。- 返回:
- 如果选择正在进行一系列更改,则为真
- 参见:
-
setSelectionMode
void setSelectionMode(int selectionMode) 设置选择模式。以下列表描述了可接受的选择模式:ListSelectionModel.SINGLE_SELECTION- 一次只能选择一个列表索引。在这种模式下,setSelectionInterval和addSelectionInterval是等效的,都用第二个参数(“lead”)表示的索引替换当前选择。ListSelectionModel.SINGLE_INTERVAL_SELECTION- 一次只能选择一个连续的间隔。在这种模式下,addSelectionInterval的行为类似于setSelectionInterval(替换当前选择),除非给定间隔与现有选择紧邻或重叠,因此可用于增长它。ListSelectionModel.MULTIPLE_INTERVAL_SELECTION- 在此模式下,可以选择的内容没有限制。
- 参数:
selectionMode- 选择模式- 抛出:
IllegalArgumentException- 如果选择模式不是允许的模式之一- 参见:
-
getSelectionMode
int getSelectionMode()返回当前选择模式。- 返回:
- 当前选择模式
- 参见:
-
addListSelectionListener
将一个监听添加到列表中,每次发生选择更改时都会通知该列表。- 参数:
x- ListSelectionListener- 参见:
-
removeListSelectionListener
从每次发生选择更改时通知的列表中删除一个监听。- 参数:
x- ListSelectionListener- 参见:
-
getSelectedIndices
default int[] getSelectedIndices()按递增顺序返回选择模型中所有选定索引的数组。- 实现要求:
-
默认实现从最小选定索引
getMinSelectionIndex()迭代到最大选定索引getMaxSelectionIndex()并在新分配的 int 数组中返回选定索引isSelectedIndex(int)。 - 返回:
- 所有选定的索引,按升序排列,如果未选择任何内容,则为空数组
- 自从:
- 11
- 参见:
-
getSelectedItemsCount
default int getSelectedItemsCount()返回所选项目的数量。- 实现要求:
-
默认实现从最小选定索引
getMinSelectionIndex()迭代到最大选定索引getMaxSelectionIndex()并返回选定索引的数量isSelectedIndex(int) - 返回:
- 所选项目的数量,如果未选择任何项目,则为 0
- 自从:
- 11
-