Search code examples
javamacoslook-and-feelfiledialog

Implement save-dialog in OSX style


I want to implement a save-dialog in my program that looks like this the save dialog in pages

Is there a way to get this in Java using Swing or AWT?

For the open-dialog, I use 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));
}

This works fine and gives a native look of OS X. But I found no equivalent for a save-dialog.

PS: I don't want to use javax.swing.JFileChooser, because it's very ugly and I want to keep the OS X style.


Solution

  • You can use the constructor that gets a mode parameter, and pass FileDialog.SAVE.

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