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

后端 未结 5 1162
抹茶落季
抹茶落季 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:09

    public void expandTree(){
        int row = 1;
        while (row++ < tree.getRowCount()){
            tree.expandRow(row);
        }
    
    public void collapseTree(){
        int row = tree.getRowCount() - 1;
        while (row-- > 0){
            tree.collapseRow(row);
        }
    }
    

提交回复
热议问题