Re: TreePath



Paul Tomblin wrote:
It seems to me that if your tree contains TreeNodes, it should be trivial
to construct a TreePath for a TreeNode by just calling ".getParent()" on
each node in turn until you reach the root, pushing each node onto the top
of a stack. So it seems almost an oversight to me that TreePath doesn't
have a constructor that takes a single TreeNode,

Yes, the JTree-related classes are missing a few things.

or that any of the known
TreeNode implementations (DefaultMutableTreeNode,
JTree.DynamicUtilTreeNode) includes a method to get a TreePath for that
node.

Well, it is not a TreeNode which is supposed to know a path. However, the output of DefaultTreeModel.getPathToRoot(TreeNode tn) can be used in a TreePath constructor. But that is via the model, not directly from a node, and only if you use (a subclass of) DefaultTreeModel.

/Thomas
--
The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
.



Relevant Pages

  • Re: TreePath
    ... So it seems almost an oversight to me that TreePath doesn't ... have a constructor that takes a single TreeNode, or that any of the known ... It has the getPath method returning an array of ...
    (comp.lang.java.gui)
  • Re: Novice question about inherited constructors
    ... class derived from TreeNode. ... The first declares a type which derives from System.Object ... the first case) the parameterless constructor in the base class. ...
    (microsoft.public.dotnet.languages.csharp)
  • JTree.expandPath & custom TreeNode & TreeModel
    ... JTree.expandPath doesn't work for me when I manually construct a TreePath ... I've implemented my own TreeNode and TreeModel. ... JTrees based on ...
    (comp.lang.java.gui)
  • TreePath
    ... to construct a TreePath for a TreeNode by just calling ".getParent" on ... So it seems almost an oversight to me that TreePath doesn't ... have a constructor that takes a single TreeNode, or that any of the known ... TreeNode implementations (DefaultMutableTreeNode, ...
    (comp.lang.java.gui)
  • Re: JTree.expandPath & custom TreeNode & TreeModel
    ... I've just fallen foul of something similar building my own tree path. ... If you hand a node to a treepath, the path contain that node, nothing ... TreeNode, so it can't do anything very much with it. ... the size of the array, then fill in the array on the way back down) ...
    (comp.lang.java.gui)