java - Expand multiple JTree nodes when user expands a node -
i have large jtree displayed in swing panel. i've implemented nodes extend defaultmutablenode, calculate children dynamically, , working well.
in cases (specifically, when expanded node has 1 child), i'd jtree expand more 1 node when use clicks expand element (recursively expanding child nodes long there 1 child, perhaps limit.
for example, if had following tree:
a - b - b2 - b3 - b4a - b4b - c - d
and user clicks expand b node, i'd b b2, , b3 nodes expanded right away.
jtree
has
public void addtreewillexpandlistener(treewillexpandlistener tel)
so should implement interface
public interface treewillexpandlistener extends eventlistener { /** * invoked whenever node in tree expanded. */ public void treewillexpand(treeexpansionevent event) throws expandvetoexception; /** * invoked whenever node in tree collapsed. */ public void treewillcollapse(treeexpansionevent event) throws expandvetoexception; }
in treewillexpand
check whether treepath
of event. if last node
in path has 1 child expand it.
Comments
Post a Comment