Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic jtree URGENT HELP REQUIRED PLS!!!!  RSS feed

 
Ahsan Hadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody:
Can anybody piont me to some examples or notes of bulding jtree with values from hierarchical query. Preferably i would like to create a class extending to DefaultMutableTreeNode or create a object and set as a userobject when building the node for the tree.
Timely response is very much appreciated.
REGARDS.
[ July 12, 2002: Message edited by: HADI ]
 
Martin Schneider
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean you have some parent-child relation on tree?
 
Ahsan Hadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a query that is returning a hierarichal type data (parent-child), I would to display that data using jtree swing. If i can see a simple example where a class has been extending to DefaultMutbaleTreeNode to form the node, that will be great help.
Regards.
 
Martin Schneider
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, here is what I have.

It is method that calls itself (recursion is the word?). Never mind those variable names And every node is an object parameters given from db. I have own class to create db-connection
edit:
here is to root:

[ July 15, 2002: Message edited by: Martin Schneider ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"HADI" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
Ahsan Hadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Martin, It is great help really appreciate your help in this regard.
Couple of questions,
1) why do u hv to call the createtree method in recurrsion.
2) within the resultset loop, you are passing an object when creating the node with DefaultMutableTreeNode. What should the state/bhaviour of this object - what should it do.
Regards and thanks again.
 
Ahsan Hadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nate, The link you provided for changing names doesnot work. If you hv access to it you can change my name to Syed Hadi.
 
Martin Schneider
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Well, with recursion you can create as "deep" tree as you want. If there is rows in table that have current node's id as parent, they will be current node's child etc. No limitation and as dynamic as possible
I dont need to do query again because I create object who has ID and all other parameters needed to display some information of them. I guess that wans't the issue here?
Hope this cleared a little bit
 
Ahsan Hadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Martin,
I got the first one.
Second question, I suppose you created a class which accepted the db values as parameters and impelmented a to_string method to return the display string for the Node. Do you do any other manipulation with the db values in newObject class.
Pls excuse my noiseness with oo prog, i am new starter beginning from the deep end.
Thanks for your help.
 
Ahsan Hadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other issue of calling the createtree method in recurrion is it established a db connection everytime which could affect db performance, and repeating it in result loop do you think it could start a indefinite loop.
Regards.
 
Martin Schneider
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use, at the moment, toString() method to display the name of node and getLevel() to make my popupmenu working correctly.
You are right. That recursion could and should be coded in some other way. Unfortunately I havent found out that solution yet
 
Ahsan Hadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Martin,
Just to give you an idea, My sql query is build using herarchical query (connect by) method, where i have to use the pseudocolumn level to form the parent-child relationship.
Regards.
 
Martin Schneider
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HADI, can you paste some code what you have there? It would be nice because I didnt understand it
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that...

The correct link is here.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!