I have JXTreeTable which I can filter. When I filter a keyword a new model is set. It works ok for me.
Now I want to expand all the filtered results. For that I save the position where the matching node was found. (It cant be a leaf.)
For that positions I create a List of TreePaths with this method:
public TreePath getPath(TreeNode node) {
List<TreeNode> list = new ArrayList<TreeNode>();
while (node != null) {
list.add(node);
node = node.getParent();
}
Collections.reverse(list);
return new TreePath(list.toArray());
}
Now I iterate over this list and call expandPath (after the new model was set) Where getTreePaths() is a list of TreePaths which I created with the method before.
for (TreePath elem : f.getTreePaths()) {
tree.expandPath(elem);
tree.scrollPathToVisible(elem);
}
But it has no effect, only the root is expanded and all the children are collapsed. In the TreePath the last element is no leaf. In a System.out in this loop I get for all:
-1 true true true
System.out.println(tree.getRowForPath(elem)); System.out.println(f.isPathValid(elem,tree.getTreeTableModel())); System.out.println(tree.isVisible(elem)); System.out.println(tree.isExpanded(elem));
The -1 for getRowForPath is maybe the problem?
isPathValid():
public boolean isPathValid(TreePath path,TreeTableModel model) {
if (path.getPathCount() == 0) {
return model.getRoot().equals(path.getPathComponent(0));
}
for (int x = 1; x < path.getPathCount(); x++) {
if (model.getIndexOfChild(path.getPathComponent(x - 1),
path.getPathComponent(x)) == -1) {
return false;
}
}
return true;
}