javaswingnetbeanslistenerjtreetable

expand/collapse listener for netbeans outline


I am using org.netbeans.swing.outline

How can I setup an expand/collapse Listener to the generated Tree?


Solution

  • The addTreeExpansionListener() method of TreePathSupport can add a conventional javax.swing.event.TreeExpansionListener.

    Addendum: For example, given an instance named outline, the following anonymous listener will print the affected path:

    TreePathSupport tps = outlineModel.getTreePathSupport();
    tps.addTreeExpansionListener(new TreeExpansionListener() {
    
        @Override
        public void treeExpanded(TreeExpansionEvent e) {
            System.out.println(e.getPath());
        }
    
        @Override
        public void treeCollapsed(TreeExpansionEvent e) {
            System.out.println(e.getPath());
        }
    });