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...
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.
Joined: Sep 11, 2012
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.
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.