M
MikeB
I find lots of material on appending items to the end of a jtree but
how do I insert a node and make every thing to the left of it it's
children.
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child 1");
root.add(child1);
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child 2");
root.add(child2);
Let's say that the above code created my tree, but later on I want to
insert a new node after child1 and make child2 the child of the newly
inserted node. So the before and after will look like the below
example.
before:
root
+ child1
+ child2
after:
root
+ child1
+ newNode
+ child2
how do I insert a node and make every thing to the left of it it's
children.
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child 1");
root.add(child1);
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child 2");
root.add(child2);
Let's say that the above code created my tree, but later on I want to
insert a new node after child1 and make child2 the child of the newly
inserted node. So the before and after will look like the below
example.
before:
root
+ child1
+ child2
after:
root
+ child1
+ newNode
+ child2