Hello,
I have been spending whole day trying to figure out why my JTree always collasped after refreshing, but I haven't got any fruit.
I have a Tree and it is collasped in the beginning, and I can expand and do some work(adding nodes or deleting nodes - no problem)
But there is a button which validates the tree, and if a node has problem, its background changes which part is working Okay.
but the tree always goes back to collasped(original state)
I tried every methods that I searched, but nothing is working.
Below is the codes..
private void validateManifest() {
CP_EditorHandler.checkManifestErrors(_contentPackage, false);
ManifestTree manifestTree = _manifestPanel.getManifestTree();
// get the selected node before updating
ManifestTreeNode selectedNode = (ManifestTreeNode) manifestTree.getSelectedNode();
// get the selected path before updating
TreePath selectedPath = (TreePath) manifestTree.getSelectionPath();
// below code is the part that recreates nodes of the tree and updates nodes' background
manifestTree.getModel().setContentPackage(_contentPackage);
// I set below code to expand to selected path
manifestTree.setExpandsSelectedPaths(true);
// I even added this code to make it sure
manifestTree.setExpandedState(selectedPath, true);
}
I even added addTreeWillExpandListener in the tree constructor, but it doesn't work either.
addTreeWillExpandListener
(new TreeWillExpandListener() {
public void treeWillExpand(TreeExpansionEvent e) { }
public void treeWillCollapse(TreeExpansionEvent e)
throws ExpandVetoException {
throw new ExpandVetoException(e, "you can't collapse this JTree");
}
});
What did I do wrong or what should I do to make it work?
I really appreciate your help.