• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 22781
131
Eclipse IDE Spring VI Editor 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:

 
reply
    Bookmark Topic Watch Topic
  • New Topic