I'm working on creating a backup application. As part of it I'm displaying the file directory of the computer in a JTree. I have been able to get everything to appear in the JTree as t is supposed to. However, no matter what I try I cannot seem to get the path of the selected file. I want to use the path to than list the selected files in the GUI as pending backup. Below I have included the code for the class as it is now where it displays the file structure. Under that is the most recent attempt to read the path. Any ideas?
The model shouldn't care about its selection - that's part of the JTree. And that has a method called getSelectionPath() (or getSelectionPaths() for multiple selection).
Rob Prime wrote:The model shouldn't care about its selection - that's part of the JTree. And that has a method called getSelectionPath() (or getSelectionPaths() for multiple selection).
Thanks for the tip. I ended up moving the selection listener outside of the TreeModel class and was able to grab it using this code in case anyone else has a similar problem:
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Getting the path of file selected in JTree item