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

Mike Hearn picture Mike Hearn · Aug 31, 2009 · Viewed 8.4k times · Source

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?

Answer

Steve McLeod picture Steve McLeod · Aug 31, 2009

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);
}