• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to use JTree?  RSS feed

 
nana Amr
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!