Java Reference
In-Depth Information
Note The keys used to select multiple nodes are look-and-feel specific. Try using the Ctrl-select or
Shift-select keyboard combinations to choose multiple nodes.
Besides changing selection modes, the remaining methods allow you to monitor attributes of
the selection path. Sometimes the methods work with row numbers, and other times they work
with TreePath objects. The selection model uses a RowMapper to map rows to paths for you. The
abstract AbstractLayoutCache class provides a basic implementation of the RowMapper interface
that is further specialized by the FixedHeightLayoutCache and VariableHeightLayoutCache
classes. You should never need to access or modify the RowMapper or any of its implementa-
tions. To map rows to paths (or paths to rows), just ask a JTree .
DefaultTreeSelectionModel Class
The DefaultTreeSelectionModel class provides an implementation of the TreeSelectionModel
interface that is initially in DISCONTIGUOUS_TREE_SELECTION mode and that supports all three
selection modes. The class introduces some of its own methods for getting listener lists; the
other methods are merely implementations of all the TreeSelectionModel interface methods,
including methods for accessing the 11 properties listed in Table 17-6. In addition,
DefaultTreeSelectionModel overrides the clone() methods of Object to be Cloneable .
Table 17-6. DefaultTreeSelectionModel Properties
Property Name
Data Type
Access
leadSelectionPath
TreePath
Read-only
leadSelectionRow
int
Read-only
maxSelectionRow
int
Read-only
minSelectionRow
int
Read-only
rowMapper
RowMapper
Read-write
selectionCount
int
Read-only
selectionEmpty
boolean
Read-only
selectionMode
int
Read-write
selectionPath
TreePath
Read-write
selectionPaths
TreePath[]
Read-write
selectionRows
int[]
Read-only
The primary reason to use the TreeSelectionModel is to change the selection mode of the
model. For instance, the following two lines of source code change the model to single-selection
mode:
 
Search WWH ::




Custom Search