This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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):