Get tree selected element as a string
Im making this program that contains a tree. The tree has a root called
Projects. Inside that there's a number of nodes representing folders.
Inside that theres a number of leaves representing text files.
How to get the name of the ancestor node and leaf as a string so i can
Assemble them in such manner to create a filepath?:)
Oh yes.. The selection type of the tree has to be single_selection
I found quite some turorials on the web but none converrted the node and leaf
To a string...
Thanks a lot:)
Re: Get tree selected element as a string
There are two approaches you can take:
1. Store the file name or a File object in the leaf node so you can get the value directly from the selected node and thus you don't need to reassemble the path.
2. Call get JTree's getSelectionPath() method to get the TreePath of the selected node and then calls it's getPath() method to get an array of the nodes from the root node up to and including the selected node. Iterate over this array and get each node's name to build your path as you go.
Re: Get tree selected element as a string