I want to make a node to reflect as a Parent node containing children (Means i need the "+" sign associated with that node when shown in JTree). Currently I am using the TreeSelectionListener interface to do some operation when a node is selected in the JTree. But I would like to do some operation only when the node is expanded using the TreeExpansionListener interface. At this point there is only a Root and say some 10 children under the root. I want all the 10 children to behave like a collapsed node (pretend they have some children within them).
Is there a way I can do this? If not how to use the TreeExpansionListener for a leaf node(bit awkward)?
Joined: May 31, 2011
I did it by adding a dummy node and then removing it in the TreeWillExpandListener interface when a node is expanded.
And the good thing is, this isn't even a trick or workaround - it's documented:
Returns true if node is a leaf. It is possible for this method to return false even if node has no children. A directory in a filesystem, for example, may contain no files; the node representing the directory is not a leaf, but it also has no children.