Link to home
Start Free TrialLog in
Avatar of rjopata
rjopata

asked on

DISCONTIGUOUS_TREE_SELECTION

DISCONTIGUOUS_TREE_SELECTION
    This is the default mode for the default tree selection model. With this mode, any combination of nodes can be selected.

I want to retrieve those nodes that are selected with the CTRL key (Metal look and feel),be it grouped or isolated.i read through the API but could'nt find the right method.Anybody knows how ?
expertmb,this time around excellent grade will be awarded.

SOLUTION
Avatar of manuel_m
manuel_m
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rjopata
rjopata

ASKER

Wow thanks Manuel.I will check ur site and get back to u.
Thanks .
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rjopata

ASKER

I had tried this method earlier.the problem i had was if one holds down the CTRL key before selecting the nodes,a loop over path.length returns correctly the selected nodes,however if a node is selected and the CTRL key is held for subsequent selections ,the method returns duplicate selected nodes.have u encountered this ? give it a try !!!
no i haven't encoutered that.
can you post a small compilable example that reproduces the problem.
Avatar of rjopata

ASKER

object u seem to be right.i just made a simple app and it worked fine either way.i'm in transit now and on windows.earlier i had this problem on linux and need to check with my code to see what i made wrong,but i'm convinced now something was wrong.
Thanks a lot .i guess i will have to split this one between u and Manuel.His url is very helpful.
Thanks once again and enjoy ur day.
Cheers
Avatar of rjopata

ASKER

Anybody wants to show me the way ?
i am extracting the selected paths with the following      
public void valueChanged( TreeSelectionEvent event )
      {
            if( event.getSource() == tree )
            {
                                    TreePath[] paths = tree.getSelectionPaths();
                  if(paths==null)
                      return;
                  for(int i=0;i<paths.length;i++){
                  System.out.println( "Selected paths=" + paths[i]);
                  }
                  System.out.println( "=====================" );
            }
      }
the result is the following
Selected paths=[JTree, colors]
Selected paths=[JTree, colors, blue]
Selected paths=[JTree, colors, violet]
=====================
i want to retrieve the strings colors,blue,violet in each selected path.i initially thought of using the toString() method on paths[i] and then store it in another String array and then StringTokenizer it.this appears to be pretty inefficient to me.If anybody knows how best i can go around this problem kindly enlighten me.
Thanks in advance.
NB ofcourse if u request for points it will be given.
to get the nodes use:

Object[] path = paths[i].getPath();
Avatar of rjopata

ASKER

Yes  objects  !!! thats it. ur more than my teacher now.i guess i can proceed from here.Thanks a lot.
Do u need points for this one ( i guess so or ?)
Glad I could help, no points needed :)
Avatar of rjopata

ASKER

Thats the expert for u.Thanks once again.