JTree(Vector v) - problems displaying hierarchy
Posted on 2003-12-01
In my Applet I want to populate a JTree with a Vector using constructor JTree(Vector v). The Vector contains objects of a class (MyTreeNode) extending DefaultMutableTreeNode interface, some objects are children of others. I was hoping the hierarchi was displayed in the tree, but the tree is "flat", without sub-levels. I tried to add only the top parent objects to the Vector, but their children nodes were not displayed.
How can I get the hierarchi displayed in a JTree using the JTree(Vector v) constructor?
MyTreeNode root = new MyTreeNode("new Result("Result 1"));
MyTreeNode child_1 = new MyTreeNodenew Result("Result 1.1");
MyTreeNode child_2 = new MyTreeNode(new Result("Result 1.2");
MyTreeNode child_11 = new MyTreeNode(new Result("Result 1.1.1");
MyTreeNode child_12 = new MyTreeNode(new Result("Result 1.1.2");
Vector v = new Vector();
//v.add(root);//displays only: Result 1
JTree tree = new JTree(v);
I also tried
JTree tree = new JTree(root);
but only root is displayed. I have tried to use a DefaultTreeModel:
DefaultTreeModel model = new DefaultTreeModel(root);
JTree tree = new JTree(model);
but root is the only node displayed...
Thanks for helping!!