- All Known Implementing Classes:
DefaultTreeSelectionModel
,JTree.EmptySelectionModel
The state of the tree selection is characterized by
a set of TreePaths, and optionally a set of integers. The mapping
from TreePath to integer is done by way of an instance of RowMapper.
It is not necessary for a TreeSelectionModel to have a RowMapper to
correctly operate, but without a RowMapper getSelectionRows
will return null.
A TreeSelectionModel can be configured to allow only one
path (SINGLE_TREE_SELECTION
) a number of
contiguous paths (CONTIGUOUS_TREE_SELECTION
) or a number of
discontiguous paths (DISCONTIGUOUS_TREE_SELECTION
).
A RowMapper
is used to determine if TreePaths are
contiguous.
In the absence of a RowMapper CONTIGUOUS_TREE_SELECTION
and
DISCONTIGUOUS_TREE_SELECTION
behave the same, that is they
allow any number of paths to be contained in the TreeSelectionModel.
For a selection model of CONTIGUOUS_TREE_SELECTION
any
time the paths are changed (setSelectionPath
,
addSelectionPath
...) the TreePaths are again checked to
make they are contiguous. A check of the TreePaths can also be forced
by invoking resetRowSelection
. How a set of discontiguous
TreePaths is mapped to a contiguous set is left to implementors of
this interface to enforce a particular policy.
Implementations should combine duplicate TreePaths that are added to the selection. For example, the following code
TreePath[] paths = new TreePath[] { treePath, treePath }; treeSelectionModel.setSelectionPaths(paths);should result in only one path being selected:
treePath
, and
not two copies of treePath
.
The lead TreePath is the last path that was added (or set). The lead row is then the row that corresponds to the TreePath as determined from the RowMapper.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
Selection can only be contiguous.static int
Selection can contain any number of items that are not necessarily contiguous.static int
Selection can only contain one path at a time. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.void
addSelectionPath(TreePath path)
Adds path to the current selection.void
addSelectionPaths(TreePath[] paths)
Adds paths to the current selection.void
Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.void
Empties the current selection.Returns the last path that was added.int
Returns the lead selection index.int
Returns the largest value obtained from the RowMapper for the current set of selected TreePaths.int
Returns the smallest value obtained from the RowMapper for the current set of selected TreePaths.Returns the RowMapper instance that is able to map a TreePath to a row.int
Returns the number of paths that are selected.int
Returns the current selection mode, one ofSINGLE_TREE_SELECTION
,CONTIGUOUS_TREE_SELECTION
orDISCONTIGUOUS_TREE_SELECTION
.Returns the first path in the selection.TreePath[]
Returns the paths in the selection.int[]
Returns all of the currently selected rows.boolean
isPathSelected(TreePath path)
Returns true if the path,path
, is in the current selection.boolean
isRowSelected(int row)
Returns true if the row identified byrow
is selected.boolean
Returns true if the selection is currently empty.void
Removes a PropertyChangeListener from the listener list.void
removeSelectionPath(TreePath path)
Removes path from the selection.void
removeSelectionPaths(TreePath[] paths)
Removes paths from the selection.void