| Author |
URGENT :- Creating JTree
|
Kinu Kanwar
Ranch Hand
Joined: Apr 19, 2005
Posts: 33
|
|
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
|
 |
Kinu Kanwar
Ranch Hand
Joined: Apr 19, 2005
Posts: 33
|
|
I got the problem..... First you need to create nodes and the last step should be creating JTree Kinu
|
 |
Stuart Gray
Ranch Hand
Joined: Apr 21, 2005
Posts: 410
|
|
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!
|
 |
Kinu Kanwar
Ranch Hand
Joined: Apr 19, 2005
Posts: 33
|
|
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
|
 |
Stuart Gray
Ranch Hand
Joined: Apr 21, 2005
Posts: 410
|
|
|
Well there must be some code missing because there is no variable called 'node' in that code either. But is the problem solved now?
|
 |
Kinu Kanwar
Ranch Hand
Joined: Apr 19, 2005
Posts: 33
|
|
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
|
 |
Stuart Gray
Ranch Hand
Joined: Apr 21, 2005
Posts: 410
|
|
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.
|
 |
 |
|
|
subject: URGENT :- Creating JTree
|
|
|