| Author |
Jtree with its Modules
|
seema chhetri
Ranch Hand
Joined: Feb 17, 2009
Posts: 41
|
|
Hello ,
I have made one Jtree in which its have 26 modules around when i click on any of them again all 26 modules is coming from that node please see my code and let me know what to do.
Thanks
seema
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
I couldn't compile your code because of several missing classes, but your TreeModel code looks really bogus. There are always 2 children (getChildCount), but if the JTree tries to get these it always gets a completely new object. If it then try to get the index of an object, 0 is always returned. And nothing is a leaf, ever.
The following are usual implementations:
- each object has an associated List (or array); let's call it children
- getChildCount(o) returns children.size() (children.length for the array)
- isLeaf(o) returns children.isEmpty() (children.length == 0 for the array)
- getIndexOfChild(o, child) returns children.indexOf(child) (a loop to retrieve the index for the array)
- getChild(o, index) returns children.get(index) (children[index] for the array)
Usually this List (or array) is stored as part of the object (e.g. DefaultMutableTreeNode) or can be constructed using the object.
For instance, a naive (very slow) File tree model (missing a few methods):
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
seema chhetri
Ranch Hand
Joined: Feb 17, 2009
Posts: 41
|
|
Hello,
thanks for repplying .but the main problem is that i dont want any leaf. I only want root then after this modules no child of these modules.
please tell me what can be possible for this code.
Thanks
|
 |
 |
|
|
subject: Jtree with its Modules
|
|
|