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)
          將選擇更改為當前選擇與 index0 和 index1 之間(包括兩者)索引的並集。
 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)
          將選擇更改為當前選擇與 index0 和 index1 之間(包括兩者)索引的差集。
 void setAnchorSelectionIndex(int index)
          設置 anchor 選擇索引。
 void setLeadSelectionIndex(int index)
          設置 lead 選擇索引。
 void setSelectionInterval(int index0, int index1)
          將選擇更改為在 index0 和 index1 之間(包括兩者)。
 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)
將選擇更改為在 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。


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 屬性,指示即將進行的選擇更改是否應該被視為單個更改的一部分。此屬性的值用於初始化產生 ListSelectionEvent 的 valueIsAdjusting 屬性。

例如,如果選擇被更新以回應一個使用者的拖動,那麼在拖動開始時,此屬性被設置為 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

提交錯誤或意見

版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。