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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -