-  
       
- 所有已知实现类:
 -  
         
DefaultListSelectionModel 
public interface ListSelectionModel此接口表示显示具有稳定索引的值列表的任何组件的选择的当前状态。 选择被建模为一组间隔,每个间隔表示所选列表元素的连续范围。 用于修改所选区间集的方法都采用一对索引index0和index1,它们表示闭合区间,即区间包括index0和index1。- 从以下版本开始:
 - 1.2
 - 另请参见:
 -  
         
DefaultListSelectionModel 
 
-  
        
       
-  
             
字段汇总
字段 变量和类型 字段 描述 static intMULTIPLE_INTERVAL_SELECTIONselectionMode属性的值:一次选择一个或多个连续的索引范围。static intSINGLE_INTERVAL_SELECTIONselectionMode属性的值:一次选择一个连续的索引范围。static intSINGLE_SELECTIONselectionMode属性的值:一次选择一个列表索引。 
-  
             
方法摘要
所有方法 实例方法 抽象方法 Default Methods 变量和类型 方法 描述 voidaddListSelectionListener(ListSelectionListener x)将侦听器添加到每次更改选择时通知的列表。voidaddSelectionInterval(int index0, int index1)将选择更改为当前选择的集合并且在index0和index1之间的索引。voidclearSelection()将选择更改为空集。intgetAnchorSelectionIndex()从最近一次调用setSelectionInterval(),addSelectionInterval()或removeSelectionInterval()返回第一个索引参数。intgetLeadSelectionIndex()从最近一次调用setSelectionInterval(),addSelectionInterval()或removeSelectionInterval()返回第二个索引参数。intgetMaxSelectionIndex()返回最后选择的索引,如果选择为空,则返回-1。intgetMinSelectionIndex()返回第一个选定的索引,如果选择为空,则返回-1。default int[]getSelectedIndices()返回选择模型中所有选定索引的数组,按升序排列。default intgetSelectedItemsCount()返回所选项的数量。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包括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_SELECTION
selectionMode属性的值:一次选择一个列表索引。- 另请参见:
 -  
              
setSelectionMode(int), 常数字段值 
 
-  
SINGLE_INTERVAL_SELECTION
static final int SINGLE_INTERVAL_SELECTION
selectionMode属性的值:一次选择一个连续的索引范围。- 另请参见:
 -  
              
setSelectionMode(int), 常数字段值 
 
-  
MULTIPLE_INTERVAL_SELECTION
static final int MULTIPLE_INTERVAL_SELECTION
selectionMode属性的值:一次选择一个或多个连续的索引范围。- 另请参见:
 -  
              
setSelectionMode(int), 常数字段值 
 
 -  
 
-  
             
方法详细信息
-  
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) 
 
-  
getSelectedIndices
default int[] getSelectedIndices()
返回选择模型中所有选定索引的数组,按升序排列。- 实现要求:
 - 
               默认实现从最小选定索引 
              
getMinSelectionIndex()迭代到最大选定索引getMaxSelectionIndex(),并在新分配的int数组中返回选定索引isSelectedIndex(int)。 - 结果
 - 所有选定的索引,按升序排列,如果未选择任何内容,则为空数组
 - 从以下版本开始:
 - 11
 - 另请参见:
 -  
              
removeSelectionInterval(int, int),addListSelectionListener(javax.swing.event.ListSelectionListener) 
 
-  
getSelectedItemsCount
default int getSelectedItemsCount()
返回所选项的数量。- 实现要求:
 - 
               默认实现从最小选定索引 
              
getMinSelectionIndex()迭代到最大选定索引getMaxSelectionIndex()并返回所选索引的数量isSelectedIndex(int) - 结果
 - 所选项目的数量,如果没有选择项目,则为0
 - 从以下版本开始:
 - 11
 
 
 -  
 
 -