Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the path of file selected in JTree item

 
Bill Cappoli
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks



 
Rob Spoor
Sheriff
Pie
Posts: 20380
45
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Bill Cappoli
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic