TreePath « JTree « Java Swing Q&A





1. Converting TreePaths into a JTree    stackoverflow.com

I am using Java. I have a set of Treepaths from a JTree. Now I want to create a JTree from it. Can anyone explain how it can be achieved? Example:

  • Root
    1. Colors
      • Red
      • Green
    2. Animals
      • Cat
      • Rat
I had ...

2. TreePath object    coderanch.com

3. Java's JTree (TreePath)    coderanch.com

Well, this is screwed up! Or at least it seems so. Now here's an example: DefaultMutableTreeNode rNode = new DefaultMutableTreeNode("/"); DefaultMutableTreeNode cNode = null; DefaultTreeModel tModel = new DefaultTreeModel(rNode); DefaultMutableTreeNode rNode2 = new DefaultMutableTreeNode("/"); DefaultMutableTreeNode cNode2 = null; DefaultTreeModel tModel2 = new DefaultTreeModel(rNode2); JTree jt = new JTree(tModel); JTree jt2 = new JTree(tModel2); cNode = new DefaultMutableTreeNode("demo"); cNode2 = new DefaultMutableTreeNode("demo"); ...

4. Constructing a TreePath?    coderanch.com

hello, i am using a tree to display a filesystem. the user has the option to rename a file or directory. after editing the valueForPathChanged method is invoked where the second parameter (Object value)contains the new pathname. after changing the name of a directory i want a new treepath with the new diretoryname. example: old path: c:\programme --> treepath: [c:\, c:\programme] ...

5. How to save a Selected TreePath and reuse later    coderanch.com

What I would like to do is save a SelectedPath from a JTree and after the tree is closed, at some later time, automatically expand the same path in a new tree. The new tree will probably have the same structure but not definitely and that is why I will have a new tree. I thought this would be easy and ...

6. JTree doesn't return expected value when calling tree.isVisible(treePath)    coderanch.com

Hello everyone I am trying to keep a node expanded programatically but am having no luck. I first set a nodePath to be expanded. Then I get its children. I also want to check to see if the children are expanded. If they are, then I want to keep them expanded as well. The way I am trying to do this ...

7. TreePath exception    coderanch.com

8. How to display all TreePath's in JTree?    java-forums.org

[COLOR="DarkGreen"]// declare a Vector to store the result[/COLOR] Vector pathList = new Vector(); [COLOR="DarkGreen"]// get an enumeration that will visit every tree node [/COLOR]Enumeration pathGen = ((DefaultMutableTreeNode)jtree.getModel()) .getRoot().breadthFirstEnumeration(); [COLOR="DarkGreen"]// traverse the tree and add paths to pathList [/COLOR]while (pathGen.hasMoreElements()) { // get an array of nodes from root to element TreeNode [] nodeArray = (TreeNode[])pathGen.nextElement(); [COLOR="DarkGreen"]// wrap the array as a ...