• 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

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

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)?
 
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
What's wrong with JFileChooser?
 
Florin Constantinescu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wilhelm Canaris wrote:.


Please check your private messages for an important administrative matter
 
Rob Spoor
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

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic