public class DefaultListSelectionModel extends Object implements ListSelectionModel, Cloneable, Serializable
 警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。 
ListSelectionModel 
       | Modifier and Type | Field and Description | 
|---|---|
| protected boolean | leadAnchorNotificationEnabled | 
| protected EventListenerList | listenerList | 
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION| Constructor and Description | 
|---|
| DefaultListSelectionModel() | 
| Modifier and Type | Method and Description | 
|---|---|
| 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)
              通知 
              ListSelectionListeners该选择的值,在闭区间firstIndex,lastIndex,已经改变。 | 
| protected void | fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting) | 
| int | getAnchorSelectionIndex()
              从最近调用setSelectionInterval(),addSelectionInterval()或removeSelectionInterval()返回第一个索引参数。 
             | 
| int | getLeadSelectionIndex()
              将第二个索引参数从最近的调用返回给setSelectionInterval(),addSelectionInterval()或removeSelectionInterval()。 
             | 
| <T extends EventListener> | getListeners(类<T> listenerType)
              在此模型上返回当前注册为 
              FooListener的所有对象的数组。 | 
| ListSelectionListener[] | getListSelectionListeners()
              返回在此 
              DefaultListSelectionModel上DefaultListSelectionModel的所有列表选择侦听器的DefaultListSelectionModel。 | 
| int | getMaxSelectionIndex()
              返回最后选择的索引,如果选择为空,则返回-1。 
             | 
| int | getMinSelectionIndex()
              返回第一个选择的索引,如果选择为空,则返回-1。 
             | 
| int | getSelectionMode()
              返回当前选择模式。 
             | 
| boolean | getValueIsAdjusting()
              如果选择正在进行一系列更改,则返回 
              true。 | 
| void | insertIndexInterval(int index, int length, boolean before)
              在索引之前/之后插入长度索引。 
             | 
| boolean | isLeadAnchorNotificationEnabled()
              返回 
              leadAnchorNotificationEnabled标志的值。 | 
| boolean | isSelectedIndex(int index)
              如果选择了指定的索引,则返回true。 
             | 
| boolean | isSelectionEmpty()
              如果没有选择索引,则返回true。 
             | 
| void | moveLeadSelectionIndex(int leadIndex)
              设置引导选择索引,保持所有选择值不变。 
             | 
| void | removeIndexInterval(int index0, int index1)
              从选择模型中删除间隔index0,index1(包括)中的索引。 
             | 
| void | removeListSelectionListener(ListSelectionListener l)
              从列表中删除一个侦听器,每次发生更改时都会通知该侦听器。 
             | 
| void | removeSelectionInterval(int index0, int index1)
              将选择变为当前选择的设定差异和 
              index0与index1之间的指数。 | 
| void | setAnchorSelectionIndex(int anchorIndex)
              设置锚选择索引,使所有选择值保持不变。 
             | 
| void | setLeadAnchorNotificationEnabled(boolean flag)
              设置leadAnchorNotificationEnabled标志的值。 
             | 
| void | setLeadSelectionIndex(int leadIndex)
              设置引导选择索引,确保锚和新引线之间的值全部被选中或全部被取消选择。 
             | 
| void | setSelectionInterval(int index0, int index1)
              将选择更改为 
              index0和index1包括)。 | 
| void | setSelectionMode(int selectionMode)
              设置选择模式。 
             | 
| void | setValueIsAdjusting(boolean isAdjusting)
              设置 
              valueIsAdjusting属性,其指示即将进行的选择更改是否应被视为单个更改的一部分。 | 
| String | toString()
              返回显示和标识此对象属性的字符串。 
             | 
protected EventListenerList listenerList
protected boolean leadAnchorNotificationEnabled
public int getMinSelectionIndex()
getMinSelectionIndex中的 
            ListSelectionModel 
           public int getMaxSelectionIndex()
getMaxSelectionIndex在界面 
            ListSelectionModel 
           public boolean getValueIsAdjusting()
true 。 
          getValueIsAdjusting中的 
            ListSelectionModel 
           ListSelectionModel.setValueIsAdjusting(boolean) 
           public int getSelectionMode()
getSelectionMode在接口 
            ListSelectionModel 
           ListSelectionModel.setSelectionMode(int) 
           public void setSelectionMode(int selectionMode)
ListSelectionModel.SINGLE_SELECTION - 一次只能选择一个列表索引。 在这种模式下, setSelectionInterval和addSelectionInterval是等价的,都用当前选择代替第二个参数(“lead”)表示的索引。 ListSelectionModel.SINGLE_INTERVAL_SELECTION - 一次只能选择一个连续的间隔。 在此模式下, addSelectionInterval行为类似于setSelectionInterval (替换当前选择),除非给定的间隔与现有选择紧密相邻或重叠,因此可用于增长。 ListSelectionModel.MULTIPLE_INTERVAL_SELECTION - 在这种模式下,对于什么可以选择没有限制。 setSelectionMode在界面 
            ListSelectionModel 
           IllegalArgumentException - 如果选择模式不是允许的模式之一 
           ListSelectionModel.getSelectionMode() 
           public boolean isSelectedIndex(int index)
isSelectedIndex在界面 
            ListSelectionModel 
           public boolean isSelectionEmpty()
isSelectionEmpty中的 
            ListSelectionModel 
           public void addListSelectionListener(ListSelectionListener l)
addListSelectionListener在界面 
            ListSelectionModel 
           l - ListSelectionListener 
           ListSelectionModel.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)
removeListSelectionListener在界面 
            ListSelectionModel 
           l - ListSelectionListener 
           ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener) 
           public ListSelectionListener[] getListSelectionListeners()
DefaultListSelectionModel上 
           DefaultListSelectionModel的所有列表选择侦听器的 
           DefaultListSelectionModel 。 
          ListSelectionListener s或一个空数组,如果没有列表选择侦听器当前注册 
           addListSelectionListener(javax.swing.event.ListSelectionListener) , 
            removeListSelectionListener(javax.swing.event.ListSelectionListener) 
           protected void fireValueChanged(boolean isAdjusting)
protected void fireValueChanged(int firstIndex,
                                int lastIndex) 
          ListSelectionListeners该选择的值,在闭区间 
           firstIndex , 
           lastIndex ,已经改变。 
          protected void fireValueChanged(int firstIndex,
                                int lastIndex,
                                boolean isAdjusting) 
          firstIndex - 间隔中的第一个索引 
           lastIndex - 间隔中的最后一个索引 
           isAdjusting - 如果这是一系列调整的最终变化,则为true 
           EventListenerList 
           public <T extends EventListener> T[] getListeners(类<T> listenerType)
FooListener的所有对象的数组。 
           FooListener使用addFooListener 。 
            您可以使用类文字指定listenerType参数,例如FooListener.class 。 例如,您可以使用以下代码查询DefaultListSelectionModel实例m作为其列表选择侦听器: 
  ListSelectionListener[] lsls = (ListSelectionListener[])(m.getListeners(ListSelectionListener.class));  
           如果没有这样的侦听器存在,这个方法返回一个空数组。 
          listenerType - 所请求的听众的类型; 
            此参数应指定从java.util.EventListener下降的java.util.EventListener 
           FooListener的所有对象的数组,如果没有添加此类侦听器,则为空数组 
           ClassCastException - 如果 
            listenerType没有指定实现java.util.EventListener的类或 
            java.util.EventListener 
           getListSelectionListeners() 
           public void setLeadAnchorNotificationEnabled(boolean flag)
public boolean isLeadAnchorNotificationEnabled()
leadAnchorNotificationEnabled标志的值。 
           当leadAnchorNotificationEnabled为真时,模型将生成带有范围的通知事件,其中包含所有选择的更改以及引用和锚索引的更改。 
           将标志设置为false会导致事件范围变窄,以便仅包含自上次更改以来已被选择或取消选中的元素。 
           无论哪种方式,模型都会在内部继续保持领先和固定变量。 
           默认值为true。 
           注意:可以更改引脚或锚点,而不更改选择。 通知这些更改通常很重要,例如需要在视图中更新新的线索或锚点时。 因此,当更改默认值时请注意。
leadAnchorNotificationEnabled旗 
           setLeadAnchorNotificationEnabled(boolean) 
           public void clearSelection()
public void setSelectionInterval(int index0,
                                 int index1) 
          index0和index1之间。 
           index0不得少于或等于index1 。 
            在SINGLE_SELECTION选择模式下,仅使用第二个索引。 
 如果这表示对当前选择的更改,则通知每个ListSelectionListener更改。 
 如果任一索引为-1 ,此方法不执行任何操作,无一例外返回。 否则,如果任一索引小于-1 ,则抛出一个IndexOutOfBoundsException 。 
setSelectionInterval在界面 
            ListSelectionModel 
           index0 - 间隔的一端。 
           index1 - 间隔的另一端 
           IndexOutOfBoundsException - 如果任一指数小于 
            -1 (且指数 
            -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 。 
addSelectionInterval在界面 
            ListSelectionModel 
           index0 - 间隔的一端。 
           index1 - 间隔的另一端 
           IndexOutOfBoundsException - 如果任一指数小于 
            -1 (且指数 
            -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 。 
removeSelectionInterval在界面 
            ListSelectionModel 
           index0 - 间隔的一端 
           index1 - 间隔的另一端 
           IndexOutOfBoundsException - 如果任一指数小于 
            -1 (既不是指数是 
            -1 ) 
           addListSelectionListener(javax.swing.event.ListSelectionListener) 
           public void insertIndexInterval(int index,
                                int length,
                                boolean before) 
          insertIndexInterval在界面 
            ListSelectionModel 
           public void removeIndexInterval(int index0,
                                int index1) 
          removeIndexInterval在接口 
            ListSelectionModel 
           public void setValueIsAdjusting(boolean isAdjusting)
valueIsAdjusting属性,其指示即将到来的选择更改是否应被视为单个更改的一部分。 
           该属性的值用于初始化生成的ListSelectionEvent s的valueIsAdjusting属性。 
            例如,如果选择是响应于用户拖动被更新,该属性可以被设置为true当拖动开始,并设置为false当拖动结束。 在拖动期间,监听器接收到valueIsAdjusting属性设置为true 。 拖动结束时,当更改完成时,监听器将收到一个值设置为false的事件。 如果希望仅在更改完成后更新,则侦听器可以使用此模式。 
 将此属性设置为true开始一系列将被视为单个更改的一部分的更改。 当财产更改为false时,会发送一个事件,表征整个选择更改(如果有的话),事件的valueIsAdjusting属性设置为false 。 
setValueIsAdjusting在界面 
            ListSelectionModel 
           isAdjusting - 属性的新值 
           ListSelectionModel.getValueIsAdjusting() , 
            ListSelectionEvent.getValueIsAdjusting() 
           public Object clone() throws CloneNotSupportedException
listenerLists不重复。 
          clone在 
            Object 
           CloneNotSupportedException - 如果选择模型不同时(a)实现可克隆接口和(b)定义 
            clone方法。 
           Cloneable 
           public int getAnchorSelectionIndex()
public int getLeadSelectionIndex()
public void setAnchorSelectionIndex(int anchorIndex)
setAnchorSelectionIndex在界面 
            ListSelectionModel 
           getAnchorSelectionIndex() , 
            setLeadSelectionIndex(int) 
           public void moveLeadSelectionIndex(int leadIndex)
leadIndex - 新的铅选择指数 
           setAnchorSelectionIndex(int) , 
            setLeadSelectionIndex(int) , 
            getLeadSelectionIndex() 
           public void setLeadSelectionIndex(int leadIndex)
如果没有选择锚索引的值,则在旧范围内反向选择值并取消选择新值中的值,做同样的事情。
为此更改生成单个事件并通知所有侦听器。 为了在此事件中产生最小限制,请在单次传递中执行操作; 这样,广播的ListSelectionEvent里的第一个和最后一个索引将会引用由于这个方法而实际改变了值的单元格。 如果相反,这个操作是在两个步骤中完成的,那么对选择状态的影响将是相同的,但是会产生两个事件,并且改变的值周围的界限将会更宽,包括首先被清除以后被设置的单元格。
 该方法可以在UI类的mouseDragged方法中使用来扩展选择。 
setLeadSelectionIndex在界面 
            ListSelectionModel 
           getLeadSelectionIndex() , 
            setAnchorSelectionIndex(int) 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.