|
e1030. Preventing the Expansion or Collapse of a Node in a JTree Component
There are two ways to prevent the expansion or collapse of a node. The
first way is to listen to expansion events and veto those events that
expand or collapse particular nodes. This method allows any listener
to prevent expansion of collapse of a node (see
e1032 Listening for Expansion and Collapse Events in a JTree Component).
The second way is to override
JTree.setExpandedState(). This method is suitable if the tree
wants to impose particular expansion or collapse rules. This method
is demonstrated in this example.
JTree tree = new JTree() {
protected void setExpandedState(TreePath path, boolean state) {
// Ignore all collapse requests; collapse events will not be fired
if (state) {
super.setExpandedState(path, state);
}
}
};
e1029.
Expanding or Collapsing All Nodes in a JTree Component
© 2002 Addison-Wesley.
|