-
- 所有已知实现类:
-
DefaultListSelectionModel
public interface ListSelectionModel该接口表示显示具有稳定索引的值列表的任何组件的选择的当前状态。 选择被建模为一组间隔,每个间隔表示所选列表元素的连续范围。 修改所选间隔集合的方法都采用一对索引index0和index1,它们表示一个闭合的间隔,即间隔包括index0和index1。- 从以下版本开始:
- 1.2
- 另请参见:
-
DefaultListSelectionModel
-
-
Field Summary
Fields Modifier and Type Field 描述 static intMULTIPLE_INTERVAL_SELECTIONselectionMode属性的值:一次选择一个或多个连续的索引范围。static intSINGLE_INTERVAL_SELECTIONselectionMode属性的值:一次选择一个连续的索引范围。static intSINGLE_SELECTIONselectionMode属性的值:一次选择一个列表索引。
-
方法摘要
所有方法 接口方法 抽象方法 Modifier and Type 方法 描述 voidaddListSelectionListener(ListSelectionListener x)将侦听器添加到每次发生更改选择时通知的列表。voidaddSelectionInterval(int index0, int index1)将选择更改为当前选择的集合,以及index0和index1之间的索引。voidclearSelection()将选择更改为空集。intgetAnchorSelectionIndex()从最近调用setSelectionInterval(),addSelectionInterval()或removeSelectionInterval()返回第一个索引参数。intgetLeadSelectionIndex()将第二个索引参数从最近的调用返回给setSelectionInterval(),addSelectionInterval()或removeSelectionInterval()。intgetMaxSelectionIndex()返回上一个选定的索引,如果选择为空,则返回-1。intgetMinSelectionIndex()返回第一个选择的索引,如果选择为空,则返回-1。intgetSelectionMode()返回当前选择模式。booleangetValueIsAdjusting()如果选择正在进行一系列更改,则返回true。voidinsertIndexInterval(int index, int length, boolean before)插入length指数开始前/后index。booleanisSelectedIndex(int index)如果选择了指定的索引,则返回true。booleanisSelectionEmpty()如果没有选择索引,则返回true。voidremoveIndexInterval(int index0, int index1)从选择模型中删除间隔index0,index1(含)的索引。voidremoveListSelectionListener(ListSelectionListener x)从列表中删除一个侦听器,每次发生更改时都会通知该侦听器。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属性,其指示即将到来的选择更改是否应被视为单个更改的一部分。
-
-
-
方法详细信息
-
setSelectionInterval
void setSelectionInterval(int index0, int index1)将选择更改为index0和index1之间。index0不一定要小于或等于index1。在
SINGLE_SELECTION选择模式下,仅使用第二个索引。如果这表示对当前选择的更改,则通知每个
ListSelectionListener更改。- 参数
-
index0- 间隔的一端。 -
index1- 间隔的另一端 - 另请参见:
-
addListSelectionListener(javax.swing.event.ListSelectionListener)
-
addSelectionInterval
void addSelectionInterval(int index0, int index1)将选择更改为当前选择的集合,以及index0和index1之间的索引。index0不一定要小于或等于index1。在
SINGLE_SELECTION选择模式下,这相当于调用setSelectionInterval,而只使用第二个索引。 在SINGLE_INTERVAL_SELECTION选择模式下,该方法的行为类似于setSelectionInterval,除非给定的间隔与现有选择紧密相邻或重叠,因此可用于增长选择。如果这表示对当前选择的更改,则通知每个
ListSelectionListener更改。- 参数
-
index0- 间隔的一端。 -
index1- 间隔的另一端 - 另请参见:
-
addListSelectionListener(javax.swing.event.ListSelectionListener),setSelectionInterval(int, int)
-
removeSelectionInterval
void removeSelectionInterval(int index0, int index1)将选择更改为当前选择的设置差异和index0与index1之间的指标。index0不一定要小于等于index1。在
SINGLE_INTERVAL_SELECTION选择模式下,如果删除将产生两个不相交选择,则删除将通过更大的选择延伸。 例如,如果选择是0-10并且您提供索引5,6(按任何顺序),则所得的选择为0-4。如果这表示对当前选择的更改,则通知每个
ListSelectionListener更改。- 参数
-
index0- 间隔的一端。 -
index1- 间隔的另一端 - 另请参见:
-
addListSelectionListener(javax.swing.event.ListSelectionListener)
-
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显示带有虚线黄色轮廓的引导索引。- 结果
- 锚选择指标
- 另请参见:
-
getLeadSelectionIndex(),setSelectionInterval(int, int),addSelectionInterval(int, int)
-
setAnchorSelectionIndex
void setAnchorSelectionIndex(int index)
设置锚选择索引。- 参数
-
index- 锚选择索引 - 另请参见:
-
getAnchorSelectionIndex()
-
getLeadSelectionIndex
int getLeadSelectionIndex()
将第二个索引参数从最近的调用返回给setSelectionInterval(),addSelectionInterval()或removeSelectionInterval()。- 结果
- 主导选择指数。
- 另请参见:
-
getAnchorSelectionIndex(),setSelectionInterval(int, int),addSelectionInterval(int, int)
-
setLeadSelectionIndex
void setLeadSelectionIndex(int index)
设置主导选择指标。- 参数
-
index- 主导选择指数 - 另请参见:
-
getLeadSelectionIndex()
-
clearSelection
void clearSelection()
将选择更改为空集。 如果这表示对当前选择的更改,则通知每个ListSelectionListener。
-
isSelectionEmpty
boolean isSelectionEmpty()
如果没有选择索引,则返回true。- 结果
-
true如果没有选择索引。
-
insertIndexInterval
void insertIndexInterval(int index, int length, boolean before)插入length指数开始前/后index。 这通常被称为将选择模型与数据模型中的相应变化同步。- 参数
-
index- 间隔的开始 -
length- 间隔的长度 -
before- 如果是true,间隔插入index之前,否则间隔插入后index
-
removeIndexInterval
void removeIndexInterval(int index0, int index1)从选择模型中删除间隔index0,index1(含)的索引。 这通常被称为将选择模型宽度与数据模型中的相应变化同步。- 参数
-
index0- 间隔的开始 -
index1- 间隔的结束
-
setValueIsAdjusting
void setValueIsAdjusting(boolean valueIsAdjusting)
设置valueIsAdjusting属性,其指示即将到来的选择更改是否应被视为单个更改的一部分。 该属性的值被用来初始化valueIsAdjusting所述的属性ListSelectionEvent生成该第例如,如果响应于用户拖动来更新选择,则当拖动开始时,此属性可以设置为
true,并且在拖动完成时将其设置为false。 在拖动期间,监听器接收valueIsAdjusting属性设置为true。 拖动结束时,当更改完成时,监听器将收到一个值设置为false的事件。 如果希望仅在更改完成后更新,则侦听器可以使用此模式。将此属性设置为
true开始一系列将被视为单个更改的一部分的更改。 当该属性更改为false,会发送一个事件,表征整个选择更改(如果有的话),事件的valueIsAdjusting属性设置为false。- 参数
-
valueIsAdjusting- 物业的新价值 - 另请参见:
-
getValueIsAdjusting(),ListSelectionEvent.getValueIsAdjusting()
-
getValueIsAdjusting
boolean getValueIsAdjusting()
如果选择正在进行一系列更改,则返回true。- 结果
- 如果选择正在进行一系列更改,则为true
- 另请参见:
-
setValueIsAdjusting(boolean)
-
setSelectionMode
void setSelectionMode(int selectionMode)
设置选择模式。 以下列表描述了接受的选择模式:-
ListSelectionModel.SINGLE_SELECTION- 一次只能选择一个列表索引。 在这种模式下,setSelectionInterval和addSelectionInterval是等效的,都用当前选择代替第二个参数(“lead”)表示的索引。 -
ListSelectionModel.SINGLE_INTERVAL_SELECTION- 一次只能选择一个连续的间隔。 在此模式下,addSelectionInterval行为类似于setSelectionInterval(替换当前选择),除非给定的时间间隔与现有选择紧密相邻或重叠,因此可以用于增长。 -
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION- 在这种模式下,没有什么可以选择的限制。
- 参数
-
selectionMode- 选择模式 - 异常
-
IllegalArgumentException- 如果选择模式不是允许的选择模式之一 - 另请参见:
-
getSelectionMode()
-
-
getSelectionMode
int getSelectionMode()
返回当前选择模式。- 结果
- 当前选择模式
- 另请参见:
-
setSelectionMode(int)
-
addListSelectionListener
void addListSelectionListener(ListSelectionListener x)
将侦听器添加到每次发生更改选择时通知的列表。
-
removeListSelectionListener
void removeListSelectionListener(ListSelectionListener x)
从列表中删除一个侦听器,每次发生更改时都会通知该侦听器。- 参数
-
x- ListSelectionListener - 另请参见:
-
addListSelectionListener(javax.swing.event.ListSelectionListener)
-
-