JTree, setSelectionPath

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 ;(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top