Forums Register Login

URGENT :- Creating JTree

+Pie Number of slices to send: Send
I have some data and I want to show it as Tree Structure ... My code is

DefaultMutableTreeNode root = new DefaultMutableTreeNode("ROOT") ;
JTree tree = new JTree(root , true);
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child 1") ;
node.add( child1 );
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child 2") ;
node.add( child2 );
DefaultMutableTreeNode child3 = new DefaultMutableTreeNode("Child 3") ;
node.add( child3 );


But the above code just shows the ROOT ....

My Structure for Tree would be like that

ROOT
Child-1
Child-2
Child-3
Child-3-2
Child-3-2
Child-3-2-1
Child-4

and so one ....

I have simplified my above code so that you can grip my logic in a second ... Please help me ..Its urgent matter

Kinu
+Pie Number of slices to send: Send
I got the problem..... First you need to create nodes and the last step should be creating JTree

Kinu
+Pie Number of slices to send: Send
Well I don't know if that is the problem exactly, but in the above example you are using node.add(), but node is not defined!
+Pie Number of slices to send: Send
The correct code is

DefaultMutableTreeNode root = new DefaultMutableTreeNode("ROOT") ;
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child 1") ;
node.add( child1 );
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child 2") ;
node.add( child2 );
DefaultMutableTreeNode child3 = new DefaultMutableTreeNode("Child 3") ;
node.add( child3 );


JTree tree = new JTree(root , true); //CAll JTREE CONSTRUCTOIR AT END

Kinu
+Pie Number of slices to send: Send
Well there must be some code missing because there is no variable called 'node' in that code either. But is the problem solved now?
+Pie Number of slices to send: Send
Yes, see the difference b/w code of 1s post and 2nd post. All variables were defined correctly.

Any wayz thanks for your help.

Kinu
+Pie Number of slices to send: Send
While I see the difference between the two pieces (the constructor called is moved, I know), the reason for the difference is not apparent from the code because as I have said, the use and type of the node variable is still not clear. I see you are calling node.add(), but I still don't see where else it is used in this code.

Anyway, glad the problem is solved.
It's never done THAT before. Explain it to me tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1073 times.
Similar Threads
lists inside a list :(((
JTree last selected path component is giving null
JTree not desplaying and check boxes
I am lost , Help Me Please ...JTree
Need help with dynamic tree view
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:56:48.