JFileChooser for directories on the Mac: how to make it not suck?
Asked Answered
C

4

10

The JFileChooser in "directories only" mode on the Mac has two serious, crippling problems:

1) You cannot create directories with it

2) You cannot switch drives

This is rather a huge problem for my installer app. As far as I can tell, Apple provides no way around this problem, you can't even activate the non-native directory chooser ... so the only alternative is to find a free/open source pure-Java replacement widget.

Does anybody know of one?

Catalogue answered 31/8, 2009 at 7:37 Comment(4)
This is a duplicate: #845903Tupiguarani
...except that the other question does not address the "switch drives" part.Fortson
Hmm, both were asked by the same person apparently, with 3 month interval in between...Fortson
Yes, that was me too. I registered this time. The last question died without an answer (unfortunately "it's a usability thing" doesn't help me).Catalogue
B
8

What about using java.awt.FileDialog? It shows a native file chooser and allows creating new folders.

public static void main(String[] args) throws UnsupportedLookAndFeelException {
    JFrame frame = new JFrame();
    System.setProperty("apple.awt.fileDialogForDirectories", "true");
    FileDialog d = new FileDialog(frame);
    d.setVisible(true);
}
Baumgardner answered 31/8, 2009 at 12:24 Comment(3)
That's for picking files, not directories. I don't think it's possible to select a directory with that widget.Catalogue
I added the missing line to make it allow choosing folders. I use this in my commercial app to let users pick folders. It's much better than JFileChooserBaumgardner
I believe the behavior of FileDialog on OS X has changed. If you set apple.awt.fileDialogForDirectories to true, you actually disable the selection of files, so only directories may be selected. By not setting any system property, OS X will allow you to select either files or directories.Triceratops
C
2

I discovered that there is a magic property you can set that makes the awt filepicker do the right thing:

System.setProperty("apple.awt.fileDialogForDirectories", "true");

I vaguely recall trying this before when I was on OS X 10.4 and it didn't work, but now I'm on Leopard and it does, so I'm a happy camper.

Catalogue answered 31/8, 2009 at 20:54 Comment(0)
A
2

JFileChooser can see external drives. Navigate down from the root into /Volumes and all drives are listed there. It's not elegant, but it works...

http://lists.apple.com/archives/java-dev///2008/Feb/msg00079.html

Abuse answered 12/5, 2010 at 10:50 Comment(0)
H
2

I used JFileChooser with showDialog method and I did not have problem. I can create directories and sava as the file with the name that I like. If you use only showOpenDialog method you can not create directories

Huberman answered 6/11, 2012 at 17:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.