The working node is life of the tree. The working node is
node B??”the working node is likely to change repeatedly during the life of the tree. life of the tree.
Utilities and Useful Classes
[ 360 ]
If we were to use the addChild() method, the new node would be added as child to
working node, in this case node B. When we create a new JTree, the root node is also
initially the working node.
Notice that the arrows between child nodes and parent nodes are bi-directional.
This is because we can navigate between nodes in both directions. The JTree
pointers are unidirectional; this means that the nodes are unaware of the
encapsulating JTree object.
If we want to create a branch of nodes, when we add a new node we can pass
another parameter. When this parameter is true, the newly added node will become
the working node.
To traverse the tree we can use the reset() and getParent() methods.
The reset() method is used to set the working node to the root node. The
getParent() method is used to set the working node to the parent node of the
present working node.
Pages:
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502