javamate06
asked on
Start programming with JTree.
Can helper help me and give me a sample program to work with multi level JTree for one who is a first time programming with JTree.
Lets assume 3 level tree. and the values in arrayList or array of strings.
[Parent, child1…]
[child1, subchild1…]
Lets assume 3 level tree. and the values in arrayList or array of strings.
[Parent, child1…]
[child1, subchild1…]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how to write it with arrayList getting value
is it like this?
for (i=0;i<arrayList.size();i+ +)
DefaultMutableTreeNode parent = new DefaultMutableTreeNode ( arrayList.get(i), true )
is it like this?
for (i=0;i<arrayList.size();i+
DefaultMutableTreeNode parent = new DefaultMutableTreeNode ( arrayList.get(i), true )
How are the values organized in the array-list? Which value is the parent, which value is for the child node?
Any reason for the C grade? You could've answered my question to be more specific, for better help.
You can create nodes using this (I'll just give a small fragment):
DefaultMutableTreeNode parent = new DefaultMutableTreeNode ( "parent", true ) ; // get the value from the array-list instead of hard-coding "parent"
DefaultMutableTreeNode child = new DefaultMutableTreeNode ( "child1", true ) ;
DefaultMutableTreeNode subchild = new DefaultMutableTreeNode ( "subchild1" , true ) ;
parent.add ( child ) ;
child.add ( subchild ) ;
JTree tree = new JTree ( parent ) ;