| Author |
JTree Explorer with Desktop, My Computer, My Documents, My Network Places etc.
|
Florin Constantinescu
Greenhorn
Joined: Oct 26, 2009
Posts: 10
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
|
What's wrong with JFileChooser?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Florin Constantinescu
Greenhorn
Joined: Oct 26, 2009
Posts: 10
|
|
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
Joined: Jul 26, 2007
Posts: 8434
|
|
Wilhelm Canaris wrote:.
Please check your private messages for an important administrative matter
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Wilhelm Canaris wrote:
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
Joined: Oct 26, 2009
Posts: 10
|
|
Rob Prime wrote:
Wilhelm Canaris wrote:
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.
|
 |
 |
|
|
subject: JTree Explorer with Desktop, My Computer, My Documents, My Network Places etc.
|
|
|