Alex Schenkel
Alex Schenkel

Reputation: 832

JFileChooser: Not able to select root dir

I'm using a JFileChooser to let the user select a directory to perform a specific task on it (in fact, want to calculate the dir's recursive size). Unfortunately it seems that it is not possible to let the user choose the root dir on OS X: I can select the top dir in the drop-down (The Harddisk itself), but then the "Open" button gets disabled, as I didn't select a dir in the list (which I don't want, since those are already sub-dirs).

I use the following code to create the dialog (rather straight-forward, I thought):

JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.showOpenDialog(parent);

The result shows up as follows:

screenshot (png, 78k): open dialog, but unable to choose top dir (Disk itself)

What am I doing wrong? Is there another way doing it correct? It also don't help to use FILES_AND_DIRECTORIES mode, or a Save dialog, just the same...

Thanks alex

Upvotes: 1

Views: 384

Answers (1)

Chris
Chris

Reputation: 23171

I don't know if it's possible with JFileChooser. You could use the awt FileDialog instead:

System.setProperty("apple.awt.fileDialogForDirectories", "true");
FileDialog d = new FileDialog(frame);
d.setVisible(true);

Upvotes: 1

Related Questions