|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjavax.swing.DefaultListSelectionModel
public class DefaultListSelectionModel
列表選擇的預設資料模型。
警告:此類別的序列化物件與以後的 Swing 版本不相容。當前序列化支持適用於短期存儲,或適用於在運行相同 Swing 版本的應用程序之間進行 RMI(Remote Method Invocation,遠端方法調用)。從 1.4 版本開始,已在 java.beans 套件中添加了支持所有 JavaBeansTM 長期存儲的功能。請參見 XMLEncoder。
ListSelectionModel| 欄位摘要 | |
|---|---|
protected boolean |
leadAnchorNotificationEnabled
|
protected EventListenerList |
listenerList
|
| 從介面 javax.swing.ListSelectionModel 繼承的欄位 |
|---|
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION |
| 建構子摘要 | |
|---|---|
DefaultListSelectionModel()
|
|
| 方法摘要 | ||
|---|---|---|
void |
addListSelectionListener(ListSelectionListener l)
將偵聽器添加到每次在選擇發生更改時都得到通知的列表。 |
|
void |
addSelectionInterval(int index0,
int index1)
將選擇更改為當前選擇與 index0 和 index1(包括)之間索引的並集。 |
|
void |
clearSelection()
將該選擇更改為空集。 |
|
Object |
clone()
返回此選擇模型的具有相同選擇的副本。 |
|
protected void |
fireValueChanged(boolean isAdjusting)
通知偵聽器已經結束了一系列的調整。 |
|
protected void |
fireValueChanged(int firstIndex,
int lastIndex)
通知 ListSelectionListener 選擇的值已發生更改,該值在 firstIndex 和 lastIndex 組成的閉區間內。 |
|
protected void |
fireValueChanged(int firstIndex,
int lastIndex,
boolean isAdjusting)
|
|
int |
getAnchorSelectionIndex()
從對 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的最近調用中返回第一個索引參數。 |
|
int |
getLeadSelectionIndex()
從對 setSelectionInterval()、addSelectionInterval() 或 removeSelectionInterval() 的最近調用中返回第二個索引參數。 |
|
|
getListeners(Class<T> listenerType)
返回當前已在此模型上註冊為 FooListener 的所有物件組成的陣列。 |
|
ListSelectionListener[] |
getListSelectionListeners()
返回已在此 DefaultListSelectionModel 上註冊的所有列表選擇偵聽器組成的陣列。 |
|
int |
getMaxSelectionIndex()
返回最後選擇的索引,如果選擇為空,則返回 -1。 |
|
int |
getMinSelectionIndex()
返回第一個選擇的索引,如果選擇為空,則返回 -1。 |
|
int |
getSelectionMode()
返回當前選擇網要。 |
|
boolean |
getValueIsAdjusting()
如果選擇在進行一系列更改,則返回 true。 |
|
void |
insertIndexInterval(int index,
int length,
boolean before)
從 index 之前/之後開始插入 length 個索引。 |
|
boolean |
isLeadAnchorNotificationEnabled()
返回 leadAnchorNotificationEnabled 標誌的值。 |
|
boolean |
isSelectedIndex(int index)
如果選擇了指定的索引,則返回 true。 |
|
boolean |
isSelectionEmpty()
如果沒有選擇索引,則返回 true。 |
|
void |
moveLeadSelectionIndex(int leadIndex)
設置 lead 選擇索引,並不作更改地保留所有選擇值。 |
|
void |
removeIndexInterval(int index0,
int index1)
從選擇模型中移除 index0,index1 區間中(包括兩端點)的索引。 |
|
void |
removeListSelectionListener(ListSelectionListener l)
將偵聽器從每次在選擇發生更改時都得到通知的列表中移除。 |
|
void |
removeSelectionInterval(int index0,
int index1)
將選擇更改為當前選擇與 index0 和 index1(包括)之間索引的差集。 |
|
void |
setAnchorSelectionIndex(int anchorIndex)
設置 anchor 選擇索引,並不作更改地保留所有選擇值。 |
|
void |
setLeadAnchorNotificationEnabled(boolean flag)
設置 leadAnchorNotificationEnabled 標誌的值。 |
|
void |
setLeadSelectionIndex(int leadIndex)
設置 lead 選擇索引,確保 anchor 和新 lead 之間的值要麼全部被選定,要麼全部被取消選定。 |
|
void |
setSelectionInterval(int index0,
int index1)
將選擇更改為 index0 和 index1(包括)的範圍之間。 |
|
void |
setSelectionMode(int selectionMode)
設置選擇網要。 |
|
void |
setValueIsAdjusting(boolean isAdjusting)
設置 valueIsAdjusting 屬性,指示即將進行的選擇更改是否應該被視為單個更改的一部分。 |
|
String |
toString()
返回顯示並標識此物件的屬性的字元串。 |
|
| 從類別 java.lang.Object 繼承的方法 |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 欄位詳細資訊 |
|---|
protected EventListenerList listenerList
protected boolean leadAnchorNotificationEnabled
| 建構子詳細資訊 |
|---|
public DefaultListSelectionModel()
| 方法詳細資訊 |
|---|
public int getMinSelectionIndex()
ListSelectionModel 中的 getMinSelectionIndexpublic int getMaxSelectionIndex()
ListSelectionModel 中的 getMaxSelectionIndexpublic boolean getValueIsAdjusting()
true。
ListSelectionModel 中的 getValueIsAdjustingListSelectionModel.setValueIsAdjusting(boolean)public int getSelectionMode()
ListSelectionModel 中的 getSelectionModeListSelectionModel.setSelectionMode(int)public void setSelectionMode(int selectionMode)
ListSelectionModel.SINGLE_SELECTION - 一次只能選擇一個列表索引。在此網要中,setSelectionInterval 和 addSelectionInterval 是等效的,兩者都使用第二個參數(「lead」)所表示的索引來替換當前選擇。
ListSelectionModel.SINGLE_INTERVAL_SELECTION - 一次只能選擇一個連續索引區間。在此網要中,addSelectionInterval 行為類似於 setSelectionInterval(替換當前選擇),除非給定區間緊接現有選擇或與現有選擇重疊從而可用於增大該選擇。
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION - 在此網要中,對選擇內容無任何限制。
ListSelectionModel 中的 setSelectionModeIllegalArgumentException - 如果選擇網要不是允許的網要之一ListSelectionModel.getSelectionMode()public boolean isSelectedIndex(int index)
ListSelectionModel 中的 isSelectedIndexpublic boolean isSelectionEmpty()
ListSelectionModel 中的 isSelectionEmptypublic void addListSelectionListener(ListSelectionListener l)
ListSelectionModel 中的 addListSelectionListenerl - ListSelectionListenerListSelectionModel.removeListSelectionListener(javax.swing.event.ListSelectionListener),
ListSelectionModel.setSelectionInterval(int, int),
ListSelectionModel.addSelectionInterval(int, int),
ListSelectionModel.removeSelectionInterval(int, int),
ListSelectionModel.clearSelection(),
ListSelectionModel.insertIndexInterval(int, int, boolean),
ListSelectionModel.removeIndexInterval(int, int)public void removeListSelectionListener(ListSelectionListener l)
ListSelectionModel 中的 removeListSelectionListenerl - ListSelectionListenerListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)public ListSelectionListener[] getListSelectionListeners()
DefaultListSelectionModel 上註冊的所有列表選擇偵聽器組成的陣列。
ListSelectionListener,如果當前沒有已註冊的列表選擇偵聽器,則返回一個空陣列。addListSelectionListener(javax.swing.event.ListSelectionListener),
removeListSelectionListener(javax.swing.event.ListSelectionListener)protected void fireValueChanged(boolean isAdjusting)
protected void fireValueChanged(int firstIndex,
int lastIndex)
ListSelectionListener 選擇的值已發生更改,該值在 firstIndex 和 lastIndex 組成的閉區間內。
protected void fireValueChanged(int firstIndex,
int lastIndex,
boolean isAdjusting)
firstIndex - 區間中的第一個索引lastIndex - 區間中的最後一個索引isAdjusting - 如果這是一系列調整中的最終更改,則該參數為 trueEventListenerListpublic <T extends EventListener> T[] getListeners(Class<T> listenerType)
FooListener 的所有物件組成的陣列。FooListener 是用 addFooListener 方法註冊的。
可以使用 class 文字值來指定 listenerType 參數,如 FooListener.class。例如,可以使用下面的程式碼查詢 DefaultListSelectionModel 實例 m 的列表選擇偵聽器:
ListSelectionListener[] lsls = (ListSelectionListener[])(m.getListeners(ListSelectionListener.class));如果不存在這樣的偵聽器,則此方法將返回一個空陣列。
listenerType - 請求的偵聽器型別;該參數應該指定一個從 java.util.EventListener 繼承的介面
FooListener 的所有物件組成的陣列,如果沒有添加這樣的偵聽器,則返回一個空陣列
ClassCastException - 如果 listenerType 沒有指定實作 java.util.EventListener 的類別或介面getListSelectionListeners()public void setLeadAnchorNotificationEnabled(boolean flag)
isLeadAnchorNotificationEnabled()public boolean isLeadAnchorNotificationEnabled()
leadAnchorNotificationEnabled 標誌的值。當 leadAnchorNotificationEnabled 為 true 時,該模型產生具有限定範圍的通知事件,該範圍覆寫對選擇所做的所有更改以及對 lead 和 anchor 索引所做的更改。將標誌設置為 false 會導致事件的限定範圍縮小,使其只包括那些已選擇的或自上一次更改之後取消選擇的元素。總之,該模型將繼續內部維護 lead 和 anchor 變數。預設值為 true。
註:在不更改選擇的情況下更改 lead 或 anchor 是有可能的。通知這些更改常常很重要,比如需要在視圖中更新新的 lead 或 anchor 時。因此,在更改預設值時,一定要小心謹慎。
leadAnchorNotificationEnabled 標誌的值setLeadAnchorNotificationEnabled(boolean)public void clearSelection()
ListSelectionModel 中的 clearSelectionListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setSelectionInterval(int index0,
int index1)
index0 和 index1(包括)的範圍之間。index0 不必小於等於 index1。
在 SINGLE_SELECTION 選擇網要中,只使用第二個索引。
如果這表示對當前選擇的更改,那麼將向每個 ListSelectionListener 通知更改。
如果任一索引為 -1,則此方法不執行任何操作,並不帶任何異常地返回。如果任一索引小於 -1,則拋出 IndexOutOfBoundsException。
ListSelectionModel 中的 setSelectionIntervalindex0 - 區間的一端index1 - 區間的另一端
IndexOutOfBoundsException - 如果任一索引小於 -1(並且兩個索引都不為 -1)addListSelectionListener(javax.swing.event.ListSelectionListener)
public void addSelectionInterval(int index0,
int index1)
index0 和 index1(包括)之間索引的並集。
在 SINGLE_SELECTION 選擇網要中,此方法等效於調用 setSelectionInterval,並且只使用第二個索引。在 SINGLE_INTERVAL_SELECTION 選擇網要中,此方法與 setSelectionInterval 的作用完全相同,除非給定區間緊接現有選擇或與現有選擇重疊從而可用於增大它。
如果這表示對當前選擇的更改,那麼將向每個 ListSelectionListener 通知更改。注意,index0 不必小於等於 index1。
如果任一索引為 -1,則此方法不執行任何操作,並不帶任何異常地返回。如果任一索引小於 -1,則拋出 IndexOutOfBoundsException。
ListSelectionModel 中的 addSelectionIntervalindex0 - 區間的一端index1 - 區間的另一端
IndexOutOfBoundsException - 如果任一索引小於 -1(並且兩個索引都不為 -1)addListSelectionListener(javax.swing.event.ListSelectionListener),
setSelectionInterval(int, int)
public void removeSelectionInterval(int index0,
int index1)
index0 和 index1(包括)之間索引的差集。index0 不必小於等於 index1。
在 SINGLE_INTERVAL_SELECTION 選擇網要中,如果移除操作將產生兩個不相交的選擇,則移除操作將通過該選擇較大的一端延伸。例如,如果選擇為 0-10,提供索引 5,6(按任意順序),則所得選擇為 0-4。
如果這表示對當前選擇的更改,那麼將向每個 ListSelectionListener 通知更改。
如果任一索引為 -1,則此方法不執行任何操作,並不帶任何異常地返回。如果任一索引小於 -1,則拋出 IndexOutOfBoundsException。
ListSelectionModel 中的 removeSelectionIntervalindex0 - 區間的一端index1 - 區間的另一端
IndexOutOfBoundsException - 如果任一索引小於 -1(並且兩個索引都不為 -1)addListSelectionListener(javax.swing.event.ListSelectionListener)
public void insertIndexInterval(int index,
int length,
boolean before)
ListSelectionModel 中的 insertIndexInterval
public void removeIndexInterval(int index0,
int index1)
ListSelectionModel 中的 removeIndexIntervalpublic void setValueIsAdjusting(boolean isAdjusting)
valueIsAdjusting 屬性,指示即將進行的選擇更改是否應該被視為單個更改的一部分。此屬性的值用於初始化產生 ListSelectionEvent 的 valueIsAdjusting 屬性。
例如,如果選擇被更新以回應一個使用者的拖動,那麼在拖動開始時,此屬性被設置為 true;在拖動結束時被設置為 false。在拖動期間,偵聽器接收 valueIsAdjusting 屬性設置為 true 的事件。在拖動的最後,當更改終止時,偵聽器接收一個值設置為 false 的事件。如果只在更改已終止時希望更新,則偵聽器可以使用此網要。
將此屬性設置為 true 將開始一系列將被視為單個更改一部分的更改。當該屬性更改回 false 時,發送一個表現整個選擇更改特徵的事件(如果有),該事件的 valueIsAdjusting 屬性設置為 false。
ListSelectionModel 中的 setValueIsAdjustingisAdjusting - 屬性的新值ListSelectionModel.getValueIsAdjusting(),
ListSelectionEvent.getValueIsAdjusting()public String toString()
Object 中的 toStringString 表示形式
public Object clone()
throws CloneNotSupportedException
listenerList 沒有被複製。
Object 中的 cloneCloneNotSupportedException - 如果選擇模型沒有 (a) 實作 Cloneable 介面且 (b) 定義一個 clone 方法。Cloneablepublic int getAnchorSelectionIndex()
ListSelectionModel 中的 getAnchorSelectionIndexListSelectionModel.getLeadSelectionIndex(),
ListSelectionModel.setSelectionInterval(int, int),
ListSelectionModel.addSelectionInterval(int, int)public int getLeadSelectionIndex()
ListSelectionModel 中的 getLeadSelectionIndexListSelectionModel.getAnchorSelectionIndex(),
ListSelectionModel.setSelectionInterval(int, int),
ListSelectionModel.addSelectionInterval(int, int)public void setAnchorSelectionIndex(int anchorIndex)
ListSelectionModel 中的 setAnchorSelectionIndexgetAnchorSelectionIndex(),
setLeadSelectionIndex(int)public void moveLeadSelectionIndex(int leadIndex)
leadIndex - 新的 lead 選擇索引setAnchorSelectionIndex(int),
setLeadSelectionIndex(int),
getLeadSelectionIndex()public void setLeadSelectionIndex(int leadIndex)
如果 anchor 索引處的值未被選定,則反過來執行上述操作:選擇原有範圍中的值,並取消選擇新範圍中的值。
為此更改產生一個事件,並通知所有偵聽器。為了在此事件中產生最小的限定範圍,要一次完成該操作;那樣廣播的 ListSelectionEvent 中第一個和最後一個索引將指出由於此方法而實際更改了其值的單元格。如果分兩步完成此操作,則選擇狀態上的效果將是相同的,但會產生兩個事件,更改值的限定範圍變得更寬,包括之前已清除但稍後又被設置的單元格。
可以在 UI 類別的 mouseDragged 方法中使用此方法來擴展選擇。
ListSelectionModel 中的 setLeadSelectionIndexgetLeadSelectionIndex(),
setAnchorSelectionIndex(int)
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。