• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Getting the path of file selected in JTree item

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Evildoers! Eat my justice! And this tiny ad's justice too!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic