以 OSX 风格实现保存对话框

Implement save-dialog in OSX style

我想在我的程序中实现一个如下所示的保存对话框

有没有一种方法可以使用 Swing 或 AWT 在 Java 中实现此功能?

对于打开对话框,我使用 java.awt.FileDialog:

public boolean getData() {
    FileDialog chooser = new FileDialog(new JFrame());

    chooser.setVisible(true);
    String chosenDir = chooser.getDirectory();
    String chosenFile = chooser.getFile();
    chooser.dispose();

    if (chosenDir == null || chosenFile == null) {
        return false;
    }

    return getLines(new File(chosenDir+chosenFile));
}

这很好用,并给出了 OS X 的原生外观。但是我没有发现保存对话框的等效项。

PS:我不想用javax.swing.JFileChooser,因为它很丑,我想保留OS X风格。

您可以使用 constructor that gets a mode parameter,并传递 FileDialog.SAVE

public FileDialog(...get the parent...,
              "Please select a place to save the file,
              FileDialog.SAVE)