File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes tree.setSelectionPath not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "tree.setSelectionPath not working" Watch "tree.setSelectionPath not working" New topic
Author

tree.setSelectionPath not working

Krithika Beri
Ranch Hand

Joined: Sep 11, 2012
Posts: 36
I have a JTree and to that i have a button called "up" which when clicked moves the node up. I am doing this by deleting the node from its place and adding it one place higher. By doing so, the node highlight is obviously going. I want to add highlight and am using setSelectionPath to do so. But it is not working...
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5



This should be inside your if statement, and it should do the work. Remove the lines after end of else from your code, because they would cancel the effect of those I wrote.
Did you check what happens if you try to move up nodes that contain children?


The quieter you are, the more you are able to hear.
Krithika Beri
Ranch Hand

Joined: Sep 11, 2012
Posts: 36
Thank you... It is working now.
Yes, that is another problem. When i try moving nodes that have children, it is becoming a normal node and it is losing all its children nodes.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

It shouldn't be too difficult to write something that moves all the children once you move their parent node.
Krithika Beri
Ranch Hand

Joined: Sep 11, 2012
Posts: 36
I have tried to add make changes for moving nodes which have children. But the problem is it is copying only selective nodes and all.
Krithika Beri
Ranch Hand

Joined: Sep 11, 2012
Posts: 36
I removed the and now alternate lines are coming. I cannot figure out where the other nodes are getting missed. Please help.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

This code does the job, based on the one you originally posted as your problem:



There are other ways to do what you want, this is just one of them. Since you got a lot of help here (even the solution for your last question) I would ask you to modify the code I posted, so that it works with more than one level child nodes (e.g. you want to move food up one level; but within it, you have 'pizza' node that also contains child nodes: four cheese pizza, grandma pizza, etc.). It is similar to the code above, and I'm sure you can work it out and many other users will find that useful.

Cheers!
 
 
subject: tree.setSelectionPath not working