Home arrow static arrow Java Programming [Archive] - JTree path question
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - JTree path question
10 Duke Stars available
This topic has 1 reply on 1 page.

Posts:1
Registered: 7/22/04
JTree path question  
Jul 22, 2004 8:43 PM



 
I have created a program that basically simulates single celled organisms in a random (non graphical) world, and I want to use a JTree to show the family history and allow the user to bring up an organism's stats by clicking on in the the Jtree, but I have a problem. Each organism has a unique ID number (starting at 0) and that's what I want to display on the tree. I have the code working to add the new organisms to the root, but I want them added as a child to the parent (each child has only one parent for these organisms), but I don't know how to do it. I tried using insertNodeInto but since everything after the root is dynamically generated I don't know how to identify the parent correctly (just using the ID doesn't seem to do anything). Do I need to create a method that somehow copies the entire treemodel into a collection and steps through it? I have the organisms in a collection already (an arraylist to be exact), so I could figure out the lineage by stepping through that, but then how do I build a 'selection path' object that will work to tell Java exactly where I want the child to go? Is the selection path just some kind of array, or is it even possible to build a selection path without a user clicking on a tree node? I hope you can figure out what I'm trying to say here and I appreciate any help you can give.
 

Posts:31,095
Registered: 4/30/99
Re: JTree path question  
Jul 22, 2004 8:51 PM (reply 1 of 1)



 
Start by creating a Map that has your organisms as the key and the nodes they are in as the value. Or just let the organism include a reference to the node that contains it. Either of those would allow you to identify the TreeNode that contains a particular organism.
 
This topic has 1 reply on 1 page.