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

試著忘記壹切 提交于 2019-12-03 07:03:48

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

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

Mike Hearn

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!