Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTree node problem?

Status
Not open for further replies.

wangdong

Programmer
Oct 28, 2004
202
CN
What I want to do that is to have two root nodes in a tree and each root node has subroots. So the tree structure will look like:

----Root 1
|-------subRoot1
|-------subRoot2
----Root 2
|-------subRoot3

I couldn't get it work. Anyone know how to do it?



Code:
DefaultMutableTreeNode[] root = {new DefaultMutableTreeNode("Root1"),new DefaultMutableTreeNode("Root2")};
			
DefaultMutableTreeNode subRoot1 = new 
     DefaultMutableTreeNode("subRoot1");
DefaultMutableTreeNode subRoot2= new 
     DefaultMutableTreeNode("subRoot2");
			
root[0].add(subRoot1);
root[0].add(subRoot2);

DefaultMutableTreeNode subRoot3= new 
    DefaultMutableTreeNode("subRoot3");

root[1].add(subRoot3);

jTree = new JTree(root);
 
Ok, I have a solution now. I need to create a node and set it visible to false. Then add more node into it.

Am I right? Or there is a simple solution?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top