next up previous
Next: JTree Class Information Up: Practical Programming of JTrees Previous: Expanding and collapsing the

Selecting and deselecting nodes

The final aspect of the JTree class which we will discuss is the technique used to select and deselect nodes within the tree.

To select a node specified in a given treepath, use code similar to the following:

TreePath path = ...
tree.setSelectionPath( path );

Trees can be selected by index also.

JTree provides a method used to clear selections, as well:

tree.clearSelection();

It is also possible to remove single nodes from the selection group. Some sample code to perform this task follows:

TreePath path = ...
tree.removeSelectionPath( path );
10.4 JTree class information



Dave Marshall
4/14/1999