javax.swing
public interface ListSelectionModel
SINGLE_SELECTION
- only one item in the list may be
selected;SINGLE_INTERVAL_SELECTION
- only one interval in the list
may be selected;MULTIPLE_INTERVAL_SELECTION
- any combination of items in
the list may be selected.ListSelectionListener
) about updates to the selection model.
This model is used to track row selections in the JList
component,
and row and column selections in the JTable
component.
Modifier and Type | Field and Description |
---|---|
static int |
MULTIPLE_INTERVAL_SELECTION
A selection mode in which any combination of items can be selected.
|
static int |
SINGLE_INTERVAL_SELECTION
A selection mode in which a single interval can be selected (an interval
is a range containing one or more contiguous items).
|
static int |
SINGLE_SELECTION
A selection mode in which only one item can be selected.
|
Modifier and Type | Method and Description |
---|---|
void |
addListSelectionListener(ListSelectionListener listener)
Registers a listener with the model so that it receives notification
of changes to the model.
|
void |
addSelectionInterval(int anchor,
int lead)
Marks the items in the specified interval as selected.
|
void |
clearSelection()
Clears the current selection from the model.
|
int |
getAnchorSelectionIndex()
Returns the index of the anchor item.
|
int |
getLeadSelectionIndex()
Returns the index of the lead item.
|
int |
getMaxSelectionIndex()
Returns the highest selected index, or
-1 if there is no
selection. |
int |
getMinSelectionIndex()
Returns the lowest selected index, or
-1 if there is no
selection. |
int |
getSelectionMode()
Returns the selection mode, which is one of
SINGLE_SELECTION ,
SINGLE_INTERVAL_SELECTION and
MULTIPLE_INTERVAL_SELECTION . |
boolean |
getValueIsAdjusting()
Returns a flag that is passed to registered listeners when changes are
made to the model.
|
void |
insertIndexInterval(int index,
int length,
boolean before)
Inserts a new interval containing
length items at the
specified index (the before flag indicates
whether the range is inserted before or after the existing item at
index ). |
boolean |
isSelectedIndex(int index)
Returns
true if the specified item is selected, and
false otherwise. |
boolean |
isSelectionEmpty()
Returns
true if there is no selection, and false
otherwise. |
void |
removeIndexInterval(int index0,
int index1)
Removes the items in the specified range (inclusive) from the selection
model.
|
void |
removeListSelectionListener(ListSelectionListener listener)
Deregisters a listener so that it no longer receives notification of
changes to the model.
|
void |
removeSelectionInterval(int anchor,
int lead)
Marks the items in the specified interval as not selected.
|
void |
setAnchorSelectionIndex(int index)
Sets the index of the anchor item.
|
void |
setLeadSelectionIndex(int index)
Sets the index of the lead item.
|
void |
setSelectionInterval(int anchor,
int lead)
Sets the selection interval to the specified range (note that
anchor can be less than, equal to, or greater than
lead ). |
void |
setSelectionMode(int mode)
Sets the selection mode.
|
void |
setValueIsAdjusting(boolean valueIsAdjusting)
Sets the flag that is passed to listeners for each change notification.
|
static final int SINGLE_SELECTION
setSelectionMode(int)
,
Constant Field Valuesstatic final int SINGLE_INTERVAL_SELECTION
setSelectionMode(int)
,
Constant Field Valuesstatic final int MULTIPLE_INTERVAL_SELECTION
setSelectionMode(int)
,
Constant Field Valuesvoid setSelectionMode(int mode)
FIXME: The spec is silent about what happens to existing selections, for example when changing from an interval selection to single selection.
mode
- one of SINGLE_SELECTION
,
SINGLE_INTERVAL_SELECTION
and
MULTIPLE_INTERVAL_SELECTION
.IllegalArgumentException
- if mode
is not one of the
specified values.getSelectionMode()
int getSelectionMode()
SINGLE_SELECTION
,
SINGLE_INTERVAL_SELECTION
and
MULTIPLE_INTERVAL_SELECTION
.setSelectionMode(int)
void clearSelection()
ListSelectionEvent
should be sent to all registered listeners.
FIXME: what happens to the anchor and lead selection indices (the spec is silent about this)? See:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4334792
int getMinSelectionIndex()
-1
if there is no
selection.getMaxSelectionIndex()
int getMaxSelectionIndex()
-1
if there is no
selection.getMinSelectionIndex()
boolean isSelectedIndex(int index)
true
if the specified item is selected, and
false
otherwise. Special note: if index
is
negative, this method should return false
(no exception
should be thrown).index
- the item index (zero-based).true
if the specified item is selected, and
false
otherwise.boolean isSelectionEmpty()
true
if there is no selection, and false
otherwise.true
if there is no selection, and
false
otherwise.void setSelectionInterval(int anchor, int lead)
anchor
can be less than, equal to, or greater than
lead
). If this results in the selection being changed,
a ListSelectionEvent
is sent to all registered listeners.
If the selection mode is SINGLE_SELECTION
, only the
lead
item is selected.
anchor
- the anchor index.lead
- the lead index.void addSelectionInterval(int anchor, int lead)
SINGLE_SELECTION
- only the lead
item is
selected;SINGLE_INTERVAL_SELECTION
- the existing selection
interval is replaced by the specified interval;MULTIPLE_INTERVAL_SELECTION
- the specified interval is
merged into the currently selected intervals.anchor
can be less than, equal to, or greater than
lead
.anchor
- the index of the anchor itemlead
- the index of the lead item.void removeSelectionInterval(int anchor, int lead)
SINGLE_SELECTION
- XXX;SINGLE_INTERVAL_SELECTION
- XXX;MULTIPLE_INTERVAL_SELECTION
- XXX.anchor
can be less than, equal to, or greater than
lead
.anchor
- the index of the anchor itemlead
- the index of the lead item.void insertIndexInterval(int index, int length, boolean before)
length
items at the
specified index
(the before
flag indicates
whether the range is inserted before or after the existing item at
index
).
FIXME: What is the selection status of the new items? Bug 4870694.
FIXME: What event is generated?index
- the index of the item.length
- the number of items in the interval to be inserted.before
- if true
, the interval should be inserted
before index
, otherwise it is inserted after.removeIndexInterval(int, int)
void removeIndexInterval(int index0, int index1)
index0
- XXXindex1
- XXXinsertIndexInterval(int, int, boolean)
int getAnchorSelectionIndex()
setAnchorSelectionIndex(int)
void setAnchorSelectionIndex(int index)
index
- the item index.getAnchorSelectionIndex()
int getLeadSelectionIndex()
setLeadSelectionIndex(int)
void setLeadSelectionIndex(int index)
index
- the item index.getLeadSelectionIndex()
void setValueIsAdjusting(boolean valueIsAdjusting)
true
at the start of the sequence, and
false
for the last change - this gives listeners the option
to ignore interim changes if that is more efficient.valueIsAdjusting
- the flag value.getValueIsAdjusting()
boolean getValueIsAdjusting()
setValueIsAdjusting(boolean)
for more information.void addListSelectionListener(ListSelectionListener listener)
listener
- the listener (null
ignored).removeListSelectionListener(ListSelectionListener)
void removeListSelectionListener(ListSelectionListener listener)
null
, this method does nothing.listener
- the listener (null
ignored).addListSelectionListener(ListSelectionListener)