• 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

how to use JTree?

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all ,,,,
i need to add a JTree to my program,i wrote one but i need it to display the content of the desktop of the computer ,i look at java tautorial and i look at googel but find nothing,
plz if somebody know plz help
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need to use the File class to discover the names of the files on the desktop, and then just create JTreeNode instances for them as normal. The files on the desktop live (under Windows 2000/XP) in three different locations:

C:\Documents and Settings\yourusername\Desktop
C:\Documents and Settings\Default User\Desktop
C:\Documents and Settings\All Users\Desktop

Create a File instance with one of these paths and then use the listFiles() method.
 
nana Amr
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i will run my program in diffrent computers so i need to change the directory path every time or thier is something else?
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you can find out the name of the current user by getting the system property "user.name". If they are not using Windows 2000/XP then yes, you will need to alter the path accordingly. You can find out the operating system with the properties "os.name" and "os.version". The final solution is likely to be a bit brittle though I'm afraid.
reply
    Bookmark Topic Watch Topic
  • New Topic