Name: el35337 Date: 05/29/98
JTree only provides two methods: expandRow() and expandPath()
to expand tree nodes. However, there is no method to get the
associated TreePath from a TreeNode.
For instance, if I create a JTree as the following:
root = new DefaultMutableTreeNode("root");
child1 = new DefaultMutableTreeNode("child1");
child2 = new DefaultMutableTreeNode("child2");
child3 = new DefaultMutableTreeNode("child3");
grandChild1 = new DefaultMutableTreeNode("grandChild1");
grandChild2 = new DefaultMutableTreeNode("grandChild2");
root.add(child1);
root.add(child2);
root.add(child3);
child2.add(grandChild1);
child3.add(grandChild2);
DefaultTreeModel treeModel = new DefaultTreeModel(root);
tree = new JTree(treeModel);
I cannot expand any particular TreeNode in JTree by specifying
the actual TreeNode object because there is no way to find out
the TreePath of the particular TreeNode among the public
methods in JTree.
I read the Swing source codes and discovered that the actual
class knowing the TreeNode and the associated TreePath
is named 'VisibleTreeNode' which provides a method called
getTreePath(). However, since the VisibleTreeNode is used by
a TreeUI object in JTree, but the TreeUI does not define an
interface method to access the VisibleTreeNode, therefore, we
cannot find a way to expand a particular tree node by specifying
a TreeNode object in JTree. JTree should provide a method to
get the TreePath from a TreeNode object, or a method
named 'expandTreeNode(TreeNode node)'.
(Review ID: 32275)
======================================================================