1

我在用org.netbeans.swing.outline

如何为生成的树设置展开/折叠侦听器?

4

1 回答 1

2

addTreeExpansionListener()方法TreePathSupport可以添加一个常规的javax.swing.event.TreeExpansionListener.

附录:例如,给定一个名为 的实例outline,以下匿名侦听器将打印受影响的路径:

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());
    }
});
于 2013-01-27T01:27:12.133 回答