problem refreshing JTree once model is changed

Hi,

Iam working with the JTreeTable component and using the following code that I found here to restore the tree to its previous state once I make changes such as insert or delete nodes.

The code basically looks like this:

int rowCount = atree.getRowCount();

Vector expandedPaths =new Vector();

for(int i=0;i<rowCount;i++)

{

TreePath treePath = atree.getPathForRow(i);

if(atree.isExpanded(treePath))

{

expandedPaths.add(treePath);

}

}

treeTableModel.fireTreeStructureChanged(tme);

for(int i=0;i<expandedPaths.size();i++)

{

atree.expandPath((TreePath)expandedPaths.get(i));

}

This works for changes where the underlying model has not changed or has not changed much. But in cases where I make lots of changes sometimes rebuilding the entire tree structure that this JTree depends on, the above code does not work.

While the data itself is correct, the expanded/collapsed state of the nodes is not maintained. Even, the tree.getRowCount() is returning the previous value. The fireTreeStructureChanged fails me in this case.

Can somebody help me in solving this problem.

cheers,

vidyut>

[1625 byte] By [vidyuta] at [2007-10-2 10:22:33]
# 1
Hi,Never mind. I solved this problem. The fireTableStructureChanged was causing the rowcount to be returned wrongly. I modified it so I retrieved the rowCount before firing the event and it is fine now.cheers,vidyut
vidyuta at 2007-7-13 1:54:40 > top of Java-index,Desktop,Core GUI APIs...