> Well since I'm only grabbing a node's children when the node is selected
> or expanded the JTree probably is using the isLeaf method from the
[quoted text clipped - 4 lines]
> still make the application behave properly. Deleting it is easy but in
> my OP I stated the trouble I ran into when I attempted that.
Sun, has provided all the functionality to implement this relatively
simply, I think however that the route you have chosen might not be
the most effective one.
Most Swing components are controlled by their models so, I would
suggest you try and implement the TreeModel or implement the TreeNode
(which is often the easier route) or a combination of both, this would
allow you to return false for the isLeaf() method. I would also
recommend to implement a TreeWillExpandListener to perform the look-up
of the child TreeNodes before the tree is expanded.
Regards,
Edwin
--
http://www.edankert.com/
Brandon McCombs - 01 Feb 2007 23:35 GMT
>> Well since I'm only grabbing a node's children when the node is selected
>> or expanded the JTree probably is using the isLeaf method from the
[quoted text clipped - 12 lines]
> suggest you try and implement the TreeModel or implement the TreeNode
> (which is often the easier route) or a combination of both, this would
My custom node already extends DefaultMutableTreeNode and I'm using the
DefaultTreeModel for the tree itself.
> allow you to return false for the isLeaf() method. I would also
> recommend to implement a TreeWillExpandListener to perform the look-up
> of the child TreeNodes before the tree is expanded.
I'll try that since Rogan also suggested that. Hopefully that will solve
the problem.
> Regards,
> Edwin
> --
> http://www.edankert.com/
Brandon McCombs - 02 Feb 2007 01:39 GMT
>>> Well since I'm only grabbing a node's children when the node is selected
>>> or expanded the JTree probably is using the isLeaf method from the
[quoted text clipped - 22 lines]
> I'll try that since Rogan also suggested that. Hopefully that will solve
> the problem.
I seemed to have fixed it by utilizing my own variable that keeps track
of the number of children that I already had in my node class. By
setting that variable to 1 when the children of a node were retrieved
and then setting it with the proper value when the children for those
children were retrieved (and overriding the isLeaf() method) I got it to
work. Since it didn't require adding fake children nodes it avoids the
problem of the tree jumping a bit when the fake child is removed just
before the real ones are added.