hi
mein JTree zeigt eine struktur aus einer DB an. die daten liegen in java als beans vor.
es funktioniert alles prächtig. refreshe ich jetzt aber mein TreeModel, und möchte anschliessend alle äste die aufgeklappt waren wieder aufklappen, funktioniert das nicht mehr, da die beans in den alten TreePath's sich auf die alten beans beziehen (beim refresh werden alle beans neu erstellt)
hat jemand eine idee wie man trotzdem die entsprechenden äste wieder aufklappen könnte? (eine idee von mir war, die ID's der einzelnen beans zu speichern, und aufgrund von diesen den baum wieder aufzuklappen... wird aber arg in die performance gehen würd ich mal sagen....)
thx im voraus & greetz
m@nu
ps. ich benutze folgenden code um den zustand der äste zu speichern und wiederherzustellen:
mein JTree zeigt eine struktur aus einer DB an. die daten liegen in java als beans vor.
es funktioniert alles prächtig. refreshe ich jetzt aber mein TreeModel, und möchte anschliessend alle äste die aufgeklappt waren wieder aufklappen, funktioniert das nicht mehr, da die beans in den alten TreePath's sich auf die alten beans beziehen (beim refresh werden alle beans neu erstellt)
hat jemand eine idee wie man trotzdem die entsprechenden äste wieder aufklappen könnte? (eine idee von mir war, die ID's der einzelnen beans zu speichern, und aufgrund von diesen den baum wieder aufzuklappen... wird aber arg in die performance gehen würd ich mal sagen....)
thx im voraus & greetz
m@nu
ps. ich benutze folgenden code um den zustand der äste zu speichern und wiederherzustellen:
Code:
/**
* Records the list of currently expanded paths in the specified tree.
* This method is meant to be called before calling the
* <code>reload()</code> methods to allow the tree to store the paths.
*
* @param tree the tree
* @param pathlist the list of expanded paths
*/
public ArrayList getExpandedPaths(JTree tree) {
ArrayList expandedPaths = new ArrayList();
addExpandedPaths(tree, tree.getPathForRow(0), expandedPaths);
return expandedPaths;
}
/**
* Adds the expanded descendants of the specifed path in the specified
* tree to the internal expanded list.
*
* @param tree the tree
* @param path the path
* @param pathlist the list of expanded paths
*/
private void addExpandedPaths(JTree tree, TreePath path, ArrayList pathlist) {
Enumeration e = tree.getExpandedDescendants(path);
if(e != null) {
while(e.hasMoreElements()) {
TreePath tp = (TreePath)e.nextElement();
pathlist.add(tp);
addExpandedPaths(tree, tp, pathlist);
}
}
}
/**
* Re-expands the expanded paths in the specified tree. This method is
* meant to be called before calling the <code>reload()</code> methods
* to allow the tree to store the paths.
*
* @param tree the tree
* @param pathlist the list of expanded paths
*/
public void expandPaths(JTree tree, ArrayList pathlist) {
for(int i = 0; i < pathlist.size(); i++) {
tree.expandPath((TreePath)pathlist.get(i));
}
}