JSheet

A Sheet is a document modal dialog that is displayed below the title bar of its owner window. JSheet roughly implements the look and feel of a Mac OS X Cocoa NSSheet component.

Quaqua Look and Feel - JSheet with a JOptionPane

JSheet provides static convenience methods for displaying JOptionPane's and JFileChooser's.

Since JSheet is only document modal, its show method does not block while the sheet is visible. You have to implement a SheetListener to get the return value of the JSheet.

Displaying a JOptionPane as a sheet

Here is how to display the option pane shown at the top of this page. Note the use of a client property for specifying the destructive choice on the sheet, and the use of the SheetListener:

JOptionPane pane = new JOptionPane(
    "<html>"+UIManager.getString("OptionPane.css")+
    "<b>Do you want to save changes to this document<br>"+
    "before closing?</b><p>"+
    "If you don't save, your changes will be lost.",
    JOptionPane.WARNING_MESSAGE
);
Object[] options = { "Save", "Cancel", "Don't Save" };
pane.setOptions(options);
pane.setInitialValue(options[0]);
pane.putClientProperty(
    "Quaqua.OptionPane.destructiveOption", new Integer(2)
);
JSheet.showSheet(pane, frame, new SheetListener() {
    public void optionSelected(SheetEvent evt) {

        Object value = evt.getValue();
        if (value == null || value.equals("Cancel")) {
           frame.setEnabled(true);
        } else if (value.equals("Don't Save")) {
           frame.dispose();
        } else if (value.equals("Save")) {
           saveChanges();
        }
    }
});

Displaying a JFileChooser as a sheet

Quaqua Look and Feel - JSheet with a JFileChooserThe following code snippet demonstrates how to display a file chooser using JSheet. Please notice the use of the SheetListener:

final JFileChooser fileChooser = new JFileChooser();
JSheet.showSaveSheet(fileChooser, frame, new SheetListener() {
    public void optionSelected(final SheetEvent evt) {

        if (evt.getOption() == JFileChooser.APPROVE_OPTION) {
            File file =

                evt.getFileChooser().getSelectedFile();
            saveToFile(file);
        }
    }
});