Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

How to get element of JTree in java

we have  price plan panel which has JTree  which contains all plans and each plan has child plans.i have to see the the query which is retriving form database and adding into this JTree .How do i seach in code where JTree is feeling the data.
0
ANISHKA1
Asked:
ANISHKA1
  • 5
  • 2
2 Solutions
 
CEHJCommented:
You need to look at what's creating a TreeModel. If you attach the source code we can advise
0
 
ANISHKA1Author Commented:
can't add code since it is company policy..Is there any way to undersatnd my question?
I am tring to explain the JTree:

PLAN1
--  ChildPlan1
--  ChildPlan2

PLAN2
--  ChildPlan1
--  ChildPlan2

PLAN2
--  ChildPlan1
--  ChildPlan2
.
.
.

we have
JTree declaration = pricePlanJTree(instance of DefaultMutableTreeNode);

then JTree is getting selection model.
then it is adding  selection listener.

And what else should i look to see where they are adding Nodes?i want to see where JTree is getting values and which query?
I hope you will understand the code?
0
 
CEHJCommented:
The best thing to do in your case is probably to look at the code for something else that create a JTree and see where they are doing similar things in your code
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CEHJCommented:
It's *you* who needs to understand your company code, not us. Look at this

http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JTree.html

and find the similarities in your source
0
 
ANISHKA1Author Commented:
i don't get it.Can you please explain it ?Generally How JTree add nodes using which code?
0
 
CEHJCommented:
That tutorial explains it all clearly. Just work through it
0
 
objectsCommented:
how is your database table structured?  
you'll need something like this:

DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
ResultSet rs = select all plans
while (rs.next()) {
   String planname = rs.getString("planname");
   DefaultMutableTreeNode plan = new DefaultMutableTreeNode(planname);
   root.add(plan);
   ResultSet rs2 = select all child plans where parent plan = planname
   while (rs2.next()) {
      String childplanname = rs2.getString("planname");
      DefaultMutableTreeNode childplan = new DefaultMutableTreeNode(childplanname);
      plan.add(childplan);
   }
}

also an example here
http://helpdesk.objects.com.au/java/how-do-i-display-tree-data-using-swing-such-as-where-i-have-a-number-of-folders-and-each-folder-has-a-number-of-children

0
 
CEHJCommented:
:-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now