【问题标题】:Implement save-dialog in OSX style以 OSX 风格实现保存对话框
【发布时间】:2016-01-17 20:54:24
【问题描述】:

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

有没有办法在 Java 中使用 Swing 或 AWT 来实现这一点?

对于打开对话框,我使用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风格。

【问题讨论】:

    标签: java macos look-and-feel filedialog


    【解决方案1】:

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

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

    【讨论】:

    • 完美,这(几乎)正是我想要的!竖起大拇指!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 2011-06-26
    • 2011-08-20
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    相关资源
    最近更新 更多