JTree
has
public void addTreeWillExpandListener(TreeWillExpandListener tel)
So you should implement the interface
public interface TreeWillExpandListener extends EventListener {
/**
* Invoked whenever a node in the tree is about to be expanded.
*/
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException;
/**
* Invoked whenever a node in the tree is about to be collapsed.
*/
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException;
}
In the treeWillExpand
check whether the TreePath
of the event. If the last Node
in the path has just one child expand it.