Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JTree, setSelectionPath

Reply
Thread Tools

JTree, setSelectionPath

 
 
Krum333
Guest
Posts: n/a
 
      03-23-2005

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()[i];
newPath[i] = 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 ;(
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Testing JTree setSelectionPath(TreePath path)? carlg@libertybasic.com Java 1 01-03-2005 04:02 AM



Advertisments