Question

I am using org.netbeans.swing.outline

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

Was it helpful?

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());
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top