问题
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?
回答1:
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);
}
回答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
回答3:
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.
回答4:
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
来源:https://stackoverflow.com/questions/1356273/jfilechooser-for-directories-on-the-mac-how-to-make-it-not-suck