How do I auto-expand a JTree when setting a new TreeModel?

后端 未结 5 1186
抹茶落季
抹茶落季 2020-12-18 19:37

I have a custom JTree and a custom JModel; I would for the JTree to \"auto-expand\" when I give it a new model. At the moment, it simply collapse a

5条回答
  •  忘掉有多难
    2020-12-18 20:29

    There's also this non-recursive version.

    private void expandAllNodes(JTree tree) {
        int j = tree.getRowCount();
        int i = 0;
        while(i < j) {
            tree.expandRow(i);
            i += 1;
            j = tree.getRowCount();
        }
    }
    

提交回复
热议问题