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
pofpof98Asked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.