JavaTM 2 Platform
Standard Ed. 6

javax.swing
接口 ListSelectionModel

所有已知实现类:
DefaultListSelectionModel

public interface ListSelectionModel

此接口表示任何组件的当前选择状态,该组件显示一个具有稳定索引的值列表。该选择被建模为一组区间,每个区间表示一个选定列表元素的连续范围。修改该组选定区间的方法都采用一对索引:index0 和 index1,这对索引表示一个闭区间,即该区间同时包括 index0 和 index1。

另请参见:
DefaultListSelectionModel

字段摘要
static int MULTIPLE_INTERVAL_SELECTION
          selectionMode 属性的值:一次选择一个或多个连续的索引范围。
static int SINGLE_INTERVAL_SELECTION
          selectionMode 属性的值:一次选择一个连续的索引范围。
static int SINGLE_SELECTION
          selectionMode 属性的值:一次选择一个列表索引。
 
方法摘要
 void addListSelectionListener(ListSelectionListener x)
          将侦听器添加到每次在选择发生更改时都得到通知的列表。
 void addSelectionInterval(int index0, int index1)
          将选择更改为当前选择与 index0index1 之间(包括两者)索引的并集。
 void clearSelection()
          将该选择更改为空集。
 int getAnchorSelectionIndex()
          从对 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的最近调用中返回第一个索引参数。
 int getLeadSelectionIndex()
          从对 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的最近调用中返回第二个索引参数。
 int getMaxSelectionIndex()
          返回最后选择的索引,如果选择为空,则返回 -1。
 int getMinSelectionIndex()
          返回第一个选择的索引,如果选择为空,则返回 -1。
 int getSelectionMode()
          返回当前选择模式。
 boolean getValueIsAdjusting()
          如果选择在进行一系列更改,则返回 true
 void insertIndexInterval(int index, int length, boolean before)
          在 index 之前/之后开始插入 length 个索引。
 boolean isSelectedIndex(int index)
          如果选择了指定的索引,则返回 true。
 boolean isSelectionEmpty()
          如果没有选择索引,则返回 true。
 void removeIndexInterval(int index0, int index1)
          从选择模型中移除区间 index0、index1(包括)中的索引。
 void removeListSelectionListener(ListSelectionListener x)
          将侦听器从每次在选择发生更改时都得到通知的列表中移除。
 void removeSelectionInterval(int index0, int index1)
          将选择更改为当前选择与 index0index1 之间(包括两者)索引的差集。
 void setAnchorSelectionIndex(int index)
          设置 anchor 选择索引。
 void setLeadSelectionIndex(int index)
          设置 lead 选择索引。
 void setSelectionInterval(int index0, int index1)
          将选择更改为在 index0index1 之间(包括两者)。
 void setSelectionMode(int selectionMode)
          设置选择模式。
 void setValueIsAdjusting(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)
将选择更改为在 index0index1 之间(包括两者)。index0 不必小于等于 index1

SINGLE_SELECTION 选择模式中,只使用第二个索引。

如果这表示对当前选择的更改,则通知每个 ListSelectionListener 该更改。

参数:
index0 - 区间的一端。
index1 - 区间的另一端
另请参见:
addListSelectionListener(javax.swing.event.ListSelectionListener)

addSelectionInterval

void addSelectionInterval(int index0,
                          int index1)
将选择更改为当前选择与 index0index1 之间(包括两者)索引的并集。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)
将选择更改为当前选择与 index0index1 之间(包括两者)索引的差集。index0 不必小于等于 index1

SINGLE_INTERVAL_SELECTION 选择模式中,如果移除操作会生成两个不相交的选择,那么移除操作将延伸到选择的较大端。例如,如果选择是 0-10,提供的索引是 5,6(按任意顺序),则所得选择是 0-4

如果这表示对当前选择的更改,则通知每个 ListSelectionListener 该更改。

参数:
index0 - 区间的一端。
index1 - 区间的另一端
另请参见:
addListSelectionListener(javax.swing.event.ListSelectionListener)

getMinSelectionIndex

int getMinSelectionIndex()
返回第一个选择的索引,如果选择为空,则返回 -1。


getMaxSelectionIndex

int getMaxSelectionIndex()
返回最后选择的索引,如果选择为空,则返回 -1。


isSelectedIndex

boolean isSelectedIndex(int index)
如果选择了指定的索引,则返回 true。


getAnchorSelectionIndex

int getAnchorSelectionIndex()
从对 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的最近调用中返回第一个索引参数。最近的 index0 被认为是 "anchor",最近的 index1 被认为是 "lead"。一些界面特别地显示这些索引,例如,Windows95 显示带有黄色点式轮廓的 lead 索引。

另请参见:
getLeadSelectionIndex(), setSelectionInterval(int, int), addSelectionInterval(int, int)

setAnchorSelectionIndex

void setAnchorSelectionIndex(int index)
设置 anchor 选择索引。

另请参见:
getAnchorSelectionIndex()

getLeadSelectionIndex

int getLeadSelectionIndex()
从对 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的最近调用中返回第二个索引参数。

另请参见:
getAnchorSelectionIndex(), setSelectionInterval(int, int), addSelectionInterval(int, int)

setLeadSelectionIndex

void setLeadSelectionIndex(int index)
设置 lead 选择索引。

另请参见:
getLeadSelectionIndex()

clearSelection

void clearSelection()
将该选择更改为空集。如果这表示对当前选择的更改,则通知每个 ListSelectionListener。

另请参见:
addListSelectionListener(javax.swing.event.ListSelectionListener)

isSelectionEmpty

boolean isSelectionEmpty()
如果没有选择索引,则返回 true。


insertIndexInterval

void insertIndexInterval(int index,
                         int length,
                         boolean before)
在 index 之前/之后开始插入 length 个索引。通常调用此方法来同步选择模型与数据模型中的相应更改。


removeIndexInterval

void removeIndexInterval(int index0,
                         int index1)
从选择模型中移除区间 index0、index1(包括)中的索引。通常调用此方法来同步选择模型与数据模型中的相应更改。


setValueIsAdjusting

void setValueIsAdjusting(boolean valueIsAdjusting)
设置 valueIsAdjusting 属性,指示即将进行的选择更改是否应该被视为单个更改的一部分。此属性的值用于初始化生成 ListSelectionEventvalueIsAdjusting 属性。

例如,如果选择被更新以响应一个用户的拖动,那么在拖动开始时,此属性被设置为 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)
设置选择模式。以下列表描述了接受的选择模式:

抛出:
IllegalArgumentException - 如果选择模式不是允许的模式之一
另请参见:
getSelectionMode()

getSelectionMode

int getSelectionMode()
返回当前选择模式。

返回:
当前选择模式
另请参见:
setSelectionMode(int)

addListSelectionListener

void addListSelectionListener(ListSelectionListener x)
将侦听器添加到每次在选择发生更改时都得到通知的列表。

参数:
x - ListSelectionListener
另请参见:
removeListSelectionListener(javax.swing.event.ListSelectionListener), setSelectionInterval(int, int), addSelectionInterval(int, int), removeSelectionInterval(int, int), clearSelection(), insertIndexInterval(int, int, boolean), removeIndexInterval(int, int)

removeListSelectionListener

void removeListSelectionListener(ListSelectionListener x)
将侦听器从每次在选择发生更改时都得到通知的列表中移除。

参数:
x - ListSelectionListener
另请参见:
addListSelectionListener(javax.swing.event.ListSelectionListener)

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策