user236501
user236501

Reputation: 8648

JTree keep expanding problem

I want to keep my jTree file expanded. I using below code to expand the jTree :

public void expandAll(JTree tree) {

    int row = 0;
    while (row < tree.getRowCount()) {
        tree.expandRow(row);
        row++;
    }
}

It works, but when I add in new file or delete file the jtree collapse back. How can keep the jTree expanded?

Upvotes: 2

Views: 837

Answers (2)

Pace
Pace

Reputation: 43907

You could extend JTree and create a JExpandedTree which overrides the add and delete methods to call expandTree afterwards.

Upvotes: 1

fasseg
fasseg

Reputation: 17761

A possibility is to save the expansionState into a local variable in your method and after manipulating the JTree you can reset the expansionState from your local variable.

check here for an example

Upvotes: 0

Related Questions