JTree, setSelectionPath

Discussion in 'Java' started by Krum333, Mar 23, 2005.

  1. Krum333

    Krum333 Guest

    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 ;(
    Krum333, Mar 23, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christophe Boutin

    double click in a jtree

    Christophe Boutin, Jul 24, 2003, in forum: Java
    Replies:
    1
    Views:
    13,066
    catalysoft.com
    Jul 25, 2003
  2. Pavel
    Replies:
    1
    Views:
    3,131
    Pavel
    Jul 25, 2003
  3. Abraham Khalil
    Replies:
    0
    Views:
    4,730
    Abraham Khalil
    Sep 17, 2003
  4. Replies:
    1
    Views:
    3,122
    Andrew Thompson
    Jan 3, 2005
  5. jumpz
    Replies:
    3
    Views:
    615
    Jean-Baptiste Nizet
    Nov 12, 2007
Loading...

Share This Page