• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

How to use TreePath and to initialise a TreePath with a string?

Hello

I have the following code :
         Object[] ObjPath = new Object[3];
        ObjPath[0]="noeud1";
        ObjPath[1]="noeud2";
       ObjPath[2]="leaf";
                     
        TreePath pathSel = new TreePath(ObjPath);
        int numRow = jTreeAutoE.getRowForPath(pathSel);

and I get numRow=-1 instead of a positive number.
What is the right code in order to get the correct numRow from the path ?
I think the TreePath object is not correctly initialised.

Thanks

Regards

AC
0
pofpof98
Asked:
pofpof98
1 Solution
 
WelkinMazeCommented:
Hi,

According to JavaDoc, -1 is returned if any of the elements in path are hidden under a collapsed parent.
Are you sure that your tree is expanded and that the path is correct?
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTree.html#getRowForPath(javax.swing.tree.TreePath)

Also you can check this one:
http://forum.java.sun.com/thread.jspa?threadID=416368&messageID=1906398
0
 
pofpof98Author Commented:
I think the path is incorrect because the  tree is expanded thanks to the following code

 for (int i=0;i<jTreeAutoE.getRowCount();i++){
                                   jTreeAutoE.expandRow(i);
                               }

I 'd like, if possible, to have an example using
Object singlePath or Object[] path
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now