Hey everyone,

I was just wondering if there is a method as part of the JTree class that would accept a parameter such as an instance of DefaultMutableTreeNode and change the content of the tree with that tree node as the root. I am looking for a method of doing what you can do with the constructor of JTree when creating the object when you can dos omething such as the following...

DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
  DefaultMutableTreeNode folder = new DefaultMutableTreeNode("Folder");
    DefaultMutableTreeNode leaf = new DefaultMutableTreeNode("Leaf");

JTree myTree = new JTree(root);

So essentially I am looking for a method like the above contruction of the JTree myTree, but I don't want to have to keep constructing a new object every time I want to change the content of the tree, as to keep the same properties of the JTree such as selection listeners etc.

If no such method exists can anyone suggest a way of doing this?


This article has been dead for over six months. Start a new discussion instead.