K
Krum333
I have an application which stores data in xml file. The xml file is read
by means of DOM and displayed in JTree. There is also a class CDNodeAdapter
which is just a container for Node object (has only getNode, setNode,
compare and toString() methods). TreeModel creates CDNodeAdapter and put
into it Node object in order to be displayed properly. Everything works
fine, but setSelctionPath doesn't ;(.
TreePath path; -- after clicking on button it is set to current tree
path
if we do just this:
setSelctionPath(path);
it will work, but this won't:
Object newPath[] = new Object[path.getPath().length];
for (int i=0; i<newPath.length; i++) {
CDNodeAdapter cdna = (CDNodeAdapter) path.getPath();
newPath = new CDNodeAdapter(cdna.getNode());
}
TreePath ntp = new TreePath(newPath);
if (ntp.equals(path)) System.out.println("Ok"); -- true
jTree1.setSelectionPath(ntp);
The equals method in CDNodeAdapter compares addresses of containing Nodes,
so equal on TreePath returns true. The getIndexOfChild in TreeModel is
proper (I think so . Anybody know what is wrong?? (or does anybody know
how setSeletionPath algorithm works; it seems to me, that it does not use
equal(Object obj), but just compares addresses ;(
by means of DOM and displayed in JTree. There is also a class CDNodeAdapter
which is just a container for Node object (has only getNode, setNode,
compare and toString() methods). TreeModel creates CDNodeAdapter and put
into it Node object in order to be displayed properly. Everything works
fine, but setSelctionPath doesn't ;(.
TreePath path; -- after clicking on button it is set to current tree
path
if we do just this:
setSelctionPath(path);
it will work, but this won't:
Object newPath[] = new Object[path.getPath().length];
for (int i=0; i<newPath.length; i++) {
CDNodeAdapter cdna = (CDNodeAdapter) path.getPath();
newPath = new CDNodeAdapter(cdna.getNode());
}
TreePath ntp = new TreePath(newPath);
if (ntp.equals(path)) System.out.println("Ok"); -- true
jTree1.setSelectionPath(ntp);
The equals method in CDNodeAdapter compares addresses of containing Nodes,
so equal on TreePath returns true. The getIndexOfChild in TreeModel is
proper (I think so . Anybody know what is wrong?? (or does anybody know
how setSeletionPath algorithm works; it seems to me, that it does not use
equal(Object obj), but just compares addresses ;(