Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree Explorer with Desktop, My Computer, My Documents, My Network Places etc.

 
Florin Constantinescu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I am building a JTree File Explorer embedded in an Applet. The explorer should display a hierarchy like this(on Windows):

- Desktop
------ My Computer
------------- C:\
------------- D:\
------------- ..............
------ My Documents
------ My Network Places
------ .............................

etc.

The problem is that I can't access the needed "virtual" paths in the hierarchy with Java methods. All I can access is something

like: THE DESKTOP PATH(as
"C:\Documents and Settings\User\Desktop"), the partitions' paths("C:\" etc) using File or FileSystemView.
What can I do to get the job done and display the tree AS ABOVE? Should I create "manually" the hierarchy above the system root

folders(I don't really like this solution)? Is there a much convenient and elegant way to do it(something like - just grab the

virtual Desktop(not the one that physically exist at "C:\Documents and Settings\User\Desktop") and and expand it using the JTree)?
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with JFileChooser?
 
Florin Constantinescu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:What's wrong with JFileChooser?


I need to display a tree there, so I don't see JFileChooser as quite appropriate for this kind of job.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wilhelm Canaris wrote:.

Please check your private messages for an important administrative matter
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wilhelm Canaris wrote:
Rob Prime wrote:What's wrong with JFileChooser?


I need to display a tree there, so I don't see JFileChooser as quite appropriate for this kind of job.

Then look for the src.zip file in your JDK folder, open it and look for the source of JFileChooser. There you can see how they did it.

Although I think I already know; check out javax.swing.filechooser.FileSystemView. Use the static factory method to get an instance, then use getRoots() to get the roots, and go one from there. A little test program to show you:
 
Florin Constantinescu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Wilhelm Canaris wrote:
Rob Prime wrote:What's wrong with JFileChooser?


I need to display a tree there, so I don't see JFileChooser as quite appropriate for this kind of job.

Then look for the src.zip file in your JDK folder, open it and look for the source of JFileChooser. There you can see how they did it.

Although I think I already know; check out javax.swing.filechooser.FileSystemView. Use the static factory method to get an instance, then use getRoots() to get the roots, and go one from there. A little test program to show you:



Thank you very much for your tips. I realized that I made a serious mistake, something like an intermediate step to sort the files. I have introduced the paths of the files obtained with view.getFiles (...) in a collection and I sorted it with Collections.sort (...). Then I recreated the files using these paths and I've formed nodes. Obviously, it's a buggy approach. The path of My Computer is displayed somewhat like this: ":: (208D2C60-3AEA-1069-A2D7-08002B30309D)"; taken from the registry keys, I presume. (N.B. I've been using a snippet where this kind of solution took shape:
http://www.java2s.com/Code/Java/Swing-JFC/DisplayafilesysteminaJTreeview.htm ,
slightly modified by me). Sorting must be done for the files returned by view.getFiles (...), using a Comparator.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic