public final class TableRowSorterListSelectionModel extends DefaultListSelectionModel
If a JTable has a RowSorter, the indices in the table's ListSelectionModel reflect the table's sort state. In other words, sorting modifies the selection indices. This makes it difficult to share ListSelectionModels for multiple JLists/JTables - which is a fundamental feature of the Presentation Model pattern. For example, if the first row is selected in unsorted state, the ListSelectionModel has a minSelectionIndex of 0. Accessing a ListModel or TableModel at row index 0 will get you the first row. Let's say you sort the table and the first row is now displayed as the third row, then the ListSelectionModel gets a minSelectionIndex of 2.
This class is used to keep an unsorted ListSelectionModel (typically provided by a presentation model) in synch with the sorted indices of the table's sorted ListSelectionModel.
Instances of this class are automatically created when using
Bindings.bind(JTable, javax.swing.ListModel, ListSelectionModel)
on a sorted table.
leadAnchorNotificationEnabled, listenerListMULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION| Constructor and Description |
|---|
TableRowSorterListSelectionModel(ListSelectionModel listSelectionModel,
JTable table) |
| Modifier and Type | Method and Description |
|---|---|
void |
addSelectionInterval(int index0,
int index1)
Changes the selection to be the set union of the current selection
and the indices between
index0 and index1 inclusive. |
void |
clearSelection()
Change the selection to the empty set.
|
int |
getSelectionMode()
Returns the current selection mode.
|
void |
insertIndexInterval(int index,
int length,
boolean before)
Insert length indices beginning before/after index.
|
void |
removeIndexInterval(int index0,
int index1)
Remove the indices in the interval index0,index1 (inclusive) from
the selection model.
|
void |
removeSelectionInterval(int index0,
int index1)
Changes the selection to be the set difference of the current selection
and the indices between
index0 and index1 inclusive. |
void |
setSelectionInterval(int index0,
int index1)
Changes the selection to be between
index0 and index1
inclusive. |
void |
setSelectionMode(int selectionMode)
Sets the selection mode.
|
addListSelectionListener, clone, fireValueChanged, fireValueChanged, fireValueChanged, getAnchorSelectionIndex, getLeadSelectionIndex, getListeners, getListSelectionListeners, getMaxSelectionIndex, getMinSelectionIndex, getValueIsAdjusting, isLeadAnchorNotificationEnabled, isSelectedIndex, isSelectionEmpty, moveLeadSelectionIndex, removeListSelectionListener, setAnchorSelectionIndex, setLeadAnchorNotificationEnabled, setLeadSelectionIndex, setValueIsAdjusting, toStringpublic TableRowSorterListSelectionModel(ListSelectionModel listSelectionModel, JTable table)
public void setSelectionInterval(int index0,
int index1)
index0 and index1
inclusive. index0 doesn't have to be less than or equal to
index1.
In SINGLE_SELECTION selection mode, only the second index
is used.
If this represents a change to the current selection, then each
ListSelectionListener is notified of the change.
setSelectionInterval in interface ListSelectionModelsetSelectionInterval in class DefaultListSelectionModelindex0 - one end of the interval.index1 - other end of the intervalDefaultListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)public void addSelectionInterval(int index0,
int index1)
index0 and index1 inclusive.
index0 doesn't have to be less than or equal to index1.
In SINGLE_SELECTION selection mode, this is equivalent
to calling setSelectionInterval, and only the second index
is used. In SINGLE_INTERVAL_SELECTION selection mode, this
method behaves like setSelectionInterval, unless the given
interval is immediately adjacent to or overlaps the existing selection,
and can therefore be used to grow the selection.
If this represents a change to the current selection, then each
ListSelectionListener is notified of the change.
addSelectionInterval in interface ListSelectionModeladdSelectionInterval in class DefaultListSelectionModelindex0 - one end of the interval.index1 - other end of the intervalDefaultListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener),
setSelectionInterval(int, int)public void removeSelectionInterval(int index0,
int index1)
index0 and index1 inclusive.
index0 doesn't have to be less than or equal to index1.
In SINGLE_INTERVAL_SELECTION selection mode, if the removal
would produce two disjoint selections, the removal is extended through
the greater end of the selection. For example, if the selection is
0-10 and you supply indices 5,6 (in any order) the
resulting selection is 0-4.
If this represents a change to the current selection, then each
ListSelectionListener is notified of the change.
removeSelectionInterval in interface ListSelectionModelremoveSelectionInterval in class DefaultListSelectionModelindex0 - one end of the interval.index1 - other end of the intervalDefaultListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)public void clearSelection()
clearSelection in interface ListSelectionModelclearSelection in class DefaultListSelectionModelDefaultListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)public void insertIndexInterval(int index,
int length,
boolean before)
insertIndexInterval in interface ListSelectionModelinsertIndexInterval in class DefaultListSelectionModelpublic void removeIndexInterval(int index0,
int index1)
removeIndexInterval in interface ListSelectionModelremoveIndexInterval in class DefaultListSelectionModelpublic void setSelectionMode(int selectionMode)
ListSelectionModel.SINGLE_SELECTION -
Only one list index can be selected at a time. In this mode,
setSelectionInterval and addSelectionInterval are
equivalent, both replacing the current selection with the index
represented by the second argument (the "lead").
ListSelectionModel.SINGLE_INTERVAL_SELECTION -
Only one contiguous interval can be selected at a time.
In this mode, addSelectionInterval behaves like
setSelectionInterval (replacing the current selection),
unless the given interval is immediately adjacent to or overlaps
the existing selection, and can therefore be used to grow it.
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION -
In this mode, there's no restriction on what can be selected.
setSelectionMode in interface ListSelectionModelsetSelectionMode in class DefaultListSelectionModelIllegalArgumentException - if the selection mode isn't
one of those allowedgetSelectionMode()public int getSelectionMode()
getSelectionMode in interface ListSelectionModelgetSelectionMode in class DefaultListSelectionModelsetSelectionMode(int)Copyright © 2002-2015 JGoodies Software GmbH. All Rights Reserved.