Re: TreePath



In article <efb9vu$271$1@xxxxxxxxxxxxxxxxx>,
ptomblin+netnews@xxxxxxxxx (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, or that any of the known
TreeNode implementations (DefaultMutableTreeNode,
JTree.DynamicUtilTreeNode) includes a method to get a TreePath for that
node.

Oh well, I guess I'll write my own TreeNode implementation that does it.

<http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/tree/DefaultMutableT
reeNode.html>

Take another look. It has the getPath method returning an array of
TreeNode, which represents the path from the root node. Since TreePath
has a constructor accepting an array of Object representing exactly that
-- the path from the root to a designated node -- I don't see what's
missing.
--
Steve W. Jackson
Montgomery, Alabama
.



Relevant Pages

  • Re: TreePath
    ... So it seems almost an oversight to me that TreePath doesn't ... have a constructor that takes a single TreeNode, ... TreeNode implementations (DefaultMutableTreeNode, ... the output of DefaultTreeModel.getPathToRootcan be used in a TreePath constructor. ...
    (comp.lang.java.gui)
  • 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)
  • 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)