Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating JTree On Run TIme

 
Kinu Kanwar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a data in this form

int node [] = 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8
int parent[] = -1 , 0 , 0 , 1 , 1 , 3 , 3 , 2 , 2

For example

node[A] = X
parent[A] = parent of X

and I ahve to draw Tree depending on relation b/w two arrays .... Any help is appreciated ...

Regards

Kinu Kanwar
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think something like this should work:




Here is some Java code (I haven't tested it though):

This assumes that nodes is an array of TreeNodes, which you could achieve like this:
 
Kinu Kanwar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not working :-(

Kinu
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't compile or doesn't run? Whats the error or problem you are getting?
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic