Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFileChooser to select a drive

 
Jerry Sun
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic