File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JFileChooser to select a drive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFileChooser to select a drive" Watch "JFileChooser to select a drive" New topic
Author

JFileChooser to select a drive

Jerry Sun
Greenhorn

Joined: Nov 05, 2001
Posts: 3
Does anyone know how to use JFileChooser to select a drive? JFileChooser won't go up to the drive level to display a list drives. Is there any way of doing it? Thanks.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
It displays them for me.
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(frame);
Try posting your code, if you still can't get it.
Jerry Sun
Greenhorn

Joined: Nov 05, 2001
Posts: 3
Thanks for fast reply.
Here is the code:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setMultiSelectionEnabled(true);
fileChooser.showOpenDialog(mainframe);
The real problem is that I can't select "C:\" or "D:\" from the JFileChooser. JFileChooser only displays directories under the root directory on the drive. Althoug drive labels are listed in the combo box, they can't be selected and return. You can't even type in "C:\" and open.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
I am not sure what the problem is I use your code and it works fine. Post the code. Also what os and jdk are you using?
Jerry Sun
Greenhorn

Joined: Nov 05, 2001
Posts: 3
Sorry, my description looks too confusing...
My question is how can you get a drive's root directory (such as "C:\") from a JFileChooser. Normally, you select a file or a directory in JFileChooser and click on "Open". But drive labels such as "C:\" are not listed in the dialog, how can you select "C:\"?
Originally posted by Paul Stevens:
I am not sure what the problem is I use your code and it works fine. Post the code. Also what os and jdk are you using?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JFileChooser to select a drive