List of usage examples for javax.swing JOptionPane createDialog
public JDialog createDialog(Component parentComponent, String title) throws HeadlessException
JDialog
wrapping this
centered on the parentComponent
in the parentComponent
's frame. From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java
/** * Create the FlatButton panel - a panel which contains graphical representations of the options available * to the user when interacting with the software. *//* w ww . j a va 2s . co m*/ private void createButtonPanel() { spreadsheetFunctionPanel = new JPanel(); spreadsheetFunctionPanel.setLayout(new BoxLayout(spreadsheetFunctionPanel, BoxLayout.LINE_AXIS)); spreadsheetFunctionPanel.setBackground(UIHelper.BG_COLOR); addRow = new JLabel(addRowButton); addRow.setToolTipText("<html><b>add row</b>" + "<p>add a new row to the table</p></html>"); addRow.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { addRow.setIcon(addRowButton); showMultipleRowsGUI(); } public void mouseEntered(MouseEvent mouseEvent) { addRow.setIcon(addRowButtonOver); } public void mouseExited(MouseEvent mouseEvent) { addRow.setIcon(addRowButton); } }); deleteRow = new JLabel(deleteRowButton); deleteRow.setToolTipText("<html><b>remove row</b>" + "<p>remove selected row from table</p></html>"); deleteRow.setEnabled(false); deleteRow.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { deleteRow.setIcon(deleteRowButton); if (table.getSelectedRow() != -1) { if (!(table.getSelectedRowCount() > 1)) { spreadsheetFunctions.deleteRow(table.getSelectedRow()); } else { spreadsheetFunctions.deleteRow(table.getSelectedRows()); } } } public void mouseEntered(MouseEvent mouseEvent) { deleteRow.setIcon(deleteRowButtonOver); } public void mouseExited(MouseEvent mouseEvent) { deleteRow.setIcon(deleteRowButton); } }); deleteColumn = new JLabel(deleteColumnButton); deleteColumn .setToolTipText("<html><b>remove column</b>" + "<p>remove selected column from table</p></html>"); deleteColumn.setEnabled(false); deleteColumn.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { deleteColumn.setIcon(deleteColumnButton); if (!(table.getSelectedColumns().length > 1)) { spreadsheetFunctions.deleteColumn(table.getSelectedColumn()); } else { showColumnErrorMessage(); } } public void mouseEntered(MouseEvent mouseEvent) { deleteColumn.setIcon(deleteColumnButtonOver); } public void mouseExited(MouseEvent mouseEvent) { deleteColumn.setIcon(deleteColumnButton); } }); multipleSort = new JLabel(multipleSortButton); multipleSort.setToolTipText( "<html><b>multiple sort</b>" + "<p>perform a multiple sort on the table</p></html>"); multipleSort.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { multipleSort.setIcon(multipleSortButton); showMultipleColumnSortGUI(); } public void mouseEntered(MouseEvent mouseEvent) { multipleSort.setIcon(multipleSortButtonOver); } public void mouseExited(MouseEvent mouseEvent) { multipleSort.setIcon(multipleSortButton); } }); copyColDown = new JLabel(copyColDownButton); copyColDown.setToolTipText("<html><b>copy column downwards</b>" + "<p>duplicate selected column and copy it from the current</p>" + "<p>position down to the final row in the table</p></html>"); copyColDown.setEnabled(false); copyColDown.addMouseListener(new MouseAdapter() { public void mouseExited(MouseEvent mouseEvent) { copyColDown.setIcon(copyColDownButton); } public void mouseEntered(MouseEvent mouseEvent) { copyColDown.setIcon(copyColDownButtonOver); } public void mousePressed(MouseEvent mouseEvent) { copyColDown.setIcon(copyColDownButton); final int row = table.getSelectedRow(); final int col = table.getSelectedColumn(); if (row != -1 && col != -1) { JOptionPane copyColDownConfirmationPane = new JOptionPane( "<html><b>Confirm Copy of Column...</b><p>Are you sure you wish to copy " + "this column downwards?</p><p>This Action can not be undone!</p></html>", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); copyColDownConfirmationPane.setIcon(copyColumnDownWarningIcon); UIHelper.applyOptionPaneBackground(copyColDownConfirmationPane, UIHelper.BG_COLOR); copyColDownConfirmationPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) { int lastOptionAnswer = Integer.valueOf(event.getNewValue().toString()); parentFrame.hideSheet(); if (lastOptionAnswer == JOptionPane.YES_OPTION) { spreadsheetFunctions.copyColumnDownwards(row, col); } } } }); parentFrame.showJDialogAsSheet( copyColDownConfirmationPane.createDialog(Spreadsheet.this, "Copy Column?")); } } }); copyRowDown = new JLabel(copyRowDownButton); copyRowDown.setToolTipText( "<html><b>copy row downwards</b>" + "<p>duplicate selected row and copy it from the current</p>" + "<p>position down to the final row</p></html>"); copyRowDown.setEnabled(false); copyRowDown.addMouseListener(new MouseAdapter() { public void mouseExited(MouseEvent mouseEvent) { copyRowDown.setIcon(copyRowDownButton); } public void mouseEntered(MouseEvent mouseEvent) { copyRowDown.setIcon(copyRowDownButtonOver); } public void mousePressed(MouseEvent mouseEvent) { copyRowDown.setIcon(copyRowDownButton); final int row = table.getSelectedRow(); JOptionPane copyRowDownConfirmationPane = new JOptionPane( "<html><b>Confirm Copy of Row...</b><p>Are you sure you wish to copy " + "this row downwards?</p><p>This Action can not be undone!</p>", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); copyRowDownConfirmationPane.setIcon(copyRowDownWarningIcon); UIHelper.applyOptionPaneBackground(copyRowDownConfirmationPane, UIHelper.BG_COLOR); copyRowDownConfirmationPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) { int lastOptionAnswer = Integer.valueOf(event.getNewValue().toString()); parentFrame.hideSheet(); if (lastOptionAnswer == JOptionPane.YES_OPTION) { spreadsheetFunctions.copyRowDownwards(row); } } } }); parentFrame.showJDialogAsSheet( copyRowDownConfirmationPane.createDialog(Spreadsheet.this, "Copy Row Down?")); } }); addProtocol = new JLabel(addProtocolButton); addProtocol.setToolTipText( "<html><b>add a protocol column</b>" + "<p>Add a protocol column to the table</p></html>"); addProtocol.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { addProtocol.setIcon(addProtocolButtonOver); } public void mouseExited(MouseEvent mouseEvent) { addProtocol.setIcon(addProtocolButton); } public void mousePressed(MouseEvent mouseEvent) { addProtocol.setIcon(addProtocolButton); if (addProtocol.isEnabled()) { FieldObject fo = new FieldObject(table.getColumnCount(), "Protocol REF", "Protocol used for experiment", DataTypes.LIST, "", false, false, false); fo.setFieldList(studyDataEntryEnvironment.getProtocolNames()); spreadsheetFunctions.addFieldToReferenceObject(fo); spreadsheetFunctions.addColumnAfterPosition("Protocol REF", null, fo.isRequired(), -1); } } }); addFactor = new JLabel(addFactorButton); addFactor.setToolTipText( "<html><b>add a factor column</b>" + "<p>Add a factor column to the table</p></html>"); addFactor.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { addFactor.setIcon(addFactorButtonOver); } public void mouseExited(MouseEvent mouseEvent) { addFactor.setIcon(addFactorButton); } public void mousePressed(MouseEvent mouseEvent) { addFactor.setIcon(addFactorButton); if (addFactor.isEnabled()) { showAddColumnsGUI(AddColumnGUI.ADD_FACTOR_COLUMN); } } }); addCharacteristic = new JLabel(addCharacteristicButton); addCharacteristic.setToolTipText("<html><b>add a characteristic column</b>" + "<p>Add a characteristic column to the table</p></html>"); addCharacteristic.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { addCharacteristic.setIcon(addCharacteristicButtonOver); } public void mouseExited(MouseEvent mouseEvent) { addCharacteristic.setIcon(addCharacteristicButton); } public void mousePressed(MouseEvent mouseEvent) { addCharacteristic.setIcon(addCharacteristicButton); if (addCharacteristic.isEnabled()) { showAddColumnsGUI(AddColumnGUI.ADD_CHARACTERISTIC_COLUMN); } } }); addParameter = new JLabel(addParameterButton); addParameter.setToolTipText( "<html><b>add a parameter column</b>" + "<p>Add a parameter column to the table</p></html>"); addParameter.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { addParameter.setIcon(addParameterButtonOver); } public void mouseExited(MouseEvent mouseEvent) { addParameter.setIcon(addParameterButton); } public void mousePressed(MouseEvent mouseEvent) { addParameter.setIcon(addParameterButton); if (addParameter.isEnabled()) { showAddColumnsGUI(AddColumnGUI.ADD_PARAMETER_COLUMN); } } }); undo = new JLabel(undoButton); undo.setToolTipText("<html><b>undo previous action<b></html>"); undo.setEnabled(undoManager.canUndo()); undo.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { undo.setIcon(undoButton); undoManager.undo(); if (highlightActive) { setRowsToDefaultColor(); } table.addNotify(); } public void mouseEntered(MouseEvent mouseEvent) { undo.setIcon(undoButtonOver); } public void mouseExited(MouseEvent mouseEvent) { undo.setIcon(undoButton); } }); redo = new JLabel(redoButton); redo.setToolTipText("<html><b>redo action<b></html>"); redo.setEnabled(undoManager.canRedo()); redo.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { redo.setIcon(redoButton); undoManager.redo(); if (highlightActive) { setRowsToDefaultColor(); } table.addNotify(); } public void mouseEntered(MouseEvent mouseEvent) { redo.setIcon(redoButtonOver); } public void mouseExited(MouseEvent mouseEvent) { redo.setIcon(redoButton); } }); transpose = new JLabel(transposeIcon); transpose.setToolTipText("<html>View a transposed version of this spreadsheet</html>"); transpose.addMouseListener(new MouseAdapter() { public void mouseExited(MouseEvent mouseEvent) { transpose.setIcon(transposeIcon); } public void mouseEntered(MouseEvent mouseEvent) { transpose.setIcon(transposeIconOver); } public void mousePressed(MouseEvent mouseEvent) { showTransposeSpreadsheetGUI(); } }); addButtons(); if (studyDataEntryEnvironment != null) { JPanel labelContainer = new JPanel(new GridLayout(1, 1)); labelContainer.setBackground(UIHelper.BG_COLOR); JLabel lab = UIHelper.createLabel(spreadsheetTitle, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, JLabel.RIGHT); lab.setBackground(UIHelper.BG_COLOR); lab.setVerticalAlignment(JLabel.CENTER); lab.setPreferredSize(new Dimension(200, 30)); labelContainer.add(lab); spreadsheetFunctionPanel.add(labelContainer); spreadsheetFunctionPanel.add(Box.createHorizontalStrut(10)); } add(spreadsheetFunctionPanel, BorderLayout.NORTH); }
From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java
private void showMessagePane(String message, int messageType) { final JOptionPane optionPane = new JOptionPane("<html>" + message + "</html>", JOptionPane.OK_OPTION); UIHelper.renderComponent(optionPane, UIHelper.VER_12_PLAIN, UIHelper.DARK_GREEN_COLOR, false); if (messageType == JOptionPane.ERROR_MESSAGE) { optionPane.setIcon(warningIcon); } else {//from www . j a va 2 s .com optionPane.setIcon(informationIcon); } optionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) { applicationContainer.hideSheet(); } } }); SwingUtilities.invokeLater(new Runnable() { public void run() { applicationContainer.showJDialogAsSheet(optionPane.createDialog(getThis(), "Message")); } }); }
From source file:org.jab.docsearch.DocSearch.java
/** * Does the actual work for Displaying an informational dialog - invoked via * a MessageRunner so as not to be on the dispatch (GUI) thread * * @see MessageRunner/* w w w . j a v a 2 s .c o m*/ */ public void showMessageDialog(String title, String body) { if (!isLoading && env.isGUIMode()) { int messageType = JOptionPane.INFORMATION_MESSAGE; if (title.toLowerCase().indexOf(I18n.getString("lower_error")) != -1) { messageType = JOptionPane.ERROR_MESSAGE; } JOptionPane pane = new JOptionPane(body, messageType); JDialog dialog = pane.createDialog(this, title); dialog.setVisible(true); } else { logger.info("showMessageDialog() \n* * * " + title + " * * *\n\t" + body); } }
From source file:org.ngrinder.recorder.ui.RecordingControlPanel.java
private boolean stopConfirm() { JOptionPane pane = new JOptionPane("Do you want to stop recording?", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION, null); JDialog dialog = pane.createDialog(SwingUtilities.getWindowAncestor(this), "Stop recording"); dialog.setVisible(true);//from w w w . j a va2 s.c om Object selectedValue = pane.getValue(); if (selectedValue == null) { return false; } return JOptionPane.YES_OPTION == (Integer) selectedValue; }
From source file:org.nuclos.client.main.MainController.java
public static void cmdOpenSettings() { NuclosSettingsContainer panel = new NuclosSettingsContainer(frm); JOptionPane p = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null); JDialog dlg = p.createDialog(Main.getInstance().getMainFrame(), SpringLocaleDelegate.getInstance().getMessage("R00022927", "Einstellungen")); dlg.pack();//from w ww . ja va2 s . c o m dlg.setResizable(true); dlg.setVisible(true); Object o = p.getValue(); int res = ((o instanceof Integer) ? ((Integer) o).intValue() : JOptionPane.CANCEL_OPTION); if (res == JOptionPane.OK_OPTION) { try { panel.save(); } catch (PreferencesException e) { Errors.getInstance().showExceptionDialog(frm, e); } } }
From source file:org.objectstyle.cayenne.modeler.editor.ObjEntityTab.java
void setEntityName(String newName) { if (newName != null && newName.trim().length() == 0) { newName = null;//from w ww.j ava2 s . co m } ObjEntity entity = mediator.getCurrentObjEntity(); if (entity == null) { return; } if (Util.nullSafeEquals(newName, entity.getName())) { return; } if (newName == null) { throw new ValidationException("Entity name is required."); } else if (entity.getDataMap().getObjEntity(newName) == null) { // completely new name, set new name for entity EntityEvent e = new EntityEvent(this, entity, entity.getName()); ProjectUtil.setObjEntityName(entity.getDataMap(), entity, newName); mediator.fireObjEntityEvent(e); // suggest to update class name String suggestedClassName = suggestedClassName(entity); if (suggestedClassName != null && !suggestedClassName.equals(entity.getClassName())) { JOptionPane pane = new JOptionPane( new Object[] { "Change class name to match new entity name?", "Suggested class name: " + suggestedClassName }, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new Object[] { "Change", "Cancel" }); pane.createDialog(Application.getFrame(), "Update Class Name").show(); if ("Change".equals(pane.getValue())) { className.setText(suggestedClassName); setClassName(suggestedClassName); } } } else { // there is an entity with the same name throw new ValidationException("There is another entity with name '" + newName + "'."); } }
From source file:org.tellervo.desktop.prefs.Prefs.java
private static boolean cantSave(Exception e) { JPanel message = new JPanel(new BorderLayout(0, 8)); // (hgap,vgap) message.add(new JLabel(I18n.getText("error.prefs_cant_save")), BorderLayout.NORTH); // -- dialog with optionpane (warning?) JOptionPane optionPane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE); JDialog dialog = optionPane.createDialog(null /* ? */, I18n.getText("error.prefs_cant_save_title")); // -- buttons: cancel, try again. optionPane.setOptions(new String[] { I18n.getText("question.try_again"), I18n.getText("general.cancel") }); // -- disclosure triangle with scrollable text area: click for // details... (stacktrace) JComponent stackTrace = new JScrollPane(new JTextArea(BugReport.getStackTrace(e), 10, 60)); JDisclosureTriangle v = new JDisclosureTriangle(I18n.getText("bug.click_for_details"), stackTrace, false); message.add(v, BorderLayout.CENTER); // -- checkbox: don't warn me again JCheckBox dontWarnCheckbox = new JCheckBox(I18n.getText("bug.dont_warn_again"), false); dontWarnCheckbox.addActionListener(new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { dontWarn = !dontWarn;//from ww w . j av a 2 s . c om } }); // FIXME: consolidate |message| panel construction with Layout methods message.add(dontWarnCheckbox, BorderLayout.SOUTH); // show dialog dialog.pack(); dialog.setResizable(false); dialog.setVisible(true); // return true if "try again" is clicked return optionPane.getValue().equals(I18n.getText("try_again")); }
From source file:org.trzcinka.intellitrac.view.toolwindow.tickets.ticket_editor.BaseTicketEditorForm.java
public BaseTicketEditorForm() { ticketsModel.getCurrentTicketModel().addListener(this); submitChangesButton.addActionListener(retrieveSubmitButtonActionListener()); changeHistoryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Window window = SwingUtilities.getWindowAncestor(rootComponent); TicketChangesHistoryPopup dialog = new TicketChangesHistoryPopup(window, ticketsModel.getCurrentTicketModel().getCurrentTicket().getChanges()); dialog.pack();/*from w ww . j a v a 2 s . c om*/ dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.dispose(); } }); downloadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Attachment attachment = (Attachment) attachmentsList.getSelectedValue(); OutputStream stream = null; if (attachment != null) { try { byte[] body = gateway.retrieveAttachment( ticketsModel.getCurrentTicketModel().getCurrentTicket().getId(), attachment.getFileName()); JFileChooser fc = new JFileChooser(); File dir = fc.getCurrentDirectory(); fc.setSelectedFile(new File(dir, attachment.getFileName())); int save = fc.showSaveDialog(rootComponent); if (save == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); stream = new FileOutputStream(file); IOUtils.write(body, stream); } } catch (ConnectionFailedException e1) { TracGatewayLocator.handleConnectionProblem(); } catch (IOException e1) { logger.error("Could not save file", e1); } finally { IOUtils.closeQuietly(stream); } } } }); showDescriptionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Attachment attachment = (Attachment) attachmentsList.getSelectedValue(); if (attachment != null) { JOptionPane popup = new AttachmentDescriptionPopup(attachment.getDescription()); JDialog dialog = popup.createDialog(null, MessageFormat.format( bundle.getString("tool_window.tickets.ticket_editor.attachments.popup_title"), attachment.getFileName())); dialog.setVisible(true); dialog.dispose(); } } }); attachmentsList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { Attachment selected = (Attachment) attachmentsList.getSelectedValue(); if (selected == null) { downloadButton.setEnabled(false); showDescriptionButton.setEnabled(false); } else { downloadButton.setEnabled(true); if (!(StringUtils.isEmpty(selected.getDescription()))) { showDescriptionButton.setEnabled(true); } } } }); newAttachmentButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Window window = SwingUtilities.getWindowAncestor(rootComponent); NewAttachmentPopup dialog = new NewAttachmentPopup(window, ticketsModel.getCurrentTicketModel().getCurrentTicket().getId()); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.dispose(); synchronizeTicket(); } }); synchronizeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { synchronizeTicket(); } }); }
From source file:pl.edu.pw.appt.GUI.java
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed boolean zal = false; JTextField z1 = new JTextField(); JTextField z2 = new JTextField(); Object[] message = { "Zdarzenie 1", z1, "Zdarzenie 2", z2 }; JOptionPane pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); pane.createDialog(null, "Badanie zdarze").setVisible(true); if (selectSystem.getSelectedIndex() != -1) { zal = server.messages.isDependent1(Integer.parseInt(z1.getText()), Integer.parseInt(z2.getText()), selectSystem.getSelectedItem().toString()); JOptionPane.showMessageDialog(null, zal ? "Zdarzenia s zalene" : "Zdarzenia s niezalene", "Badanie zdarze", JOptionPane.WARNING_MESSAGE); }/*w w w. j a v a 2 s . co m*/ }
From source file:processing.app.Editor.java
/** * Check if the sketch is modified and ask user to save changes. * @return false if canceling the close/quit operation *//*from ww w.j a v a2 s. c o m*/ protected boolean checkModified() { if (!sketch.isModified()) return true; // As of Processing 1.0.10, this always happens immediately. // http://dev.processing.org/bugs/show_bug.cgi?id=1456 toFront(); String prompt = I18n.format(_("Save changes to \"{0}\"? "), sketch.getName()); if (!OSUtils.isMacOS()) { int result = JOptionPane.showConfirmDialog(this, prompt, _("Close"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (result) { case JOptionPane.YES_OPTION: return handleSave(true); case JOptionPane.NO_OPTION: return true; // ok to continue case JOptionPane.CANCEL_OPTION: case JOptionPane.CLOSED_OPTION: // Escape key pressed return false; default: throw new IllegalStateException(); } } else { // This code is disabled unless Java 1.5 is being used on Mac OS X // because of a Java bug that prevents the initial value of the // dialog from being set properly (at least on my MacBook Pro). // The bug causes the "Don't Save" option to be the highlighted, // blinking, default. This sucks. But I'll tell you what doesn't // suck--workarounds for the Mac and Apple's snobby attitude about it! // I think it's nifty that they treat their developers like dirt. // Pane formatting adapted from the quaqua guide // http://www.randelshofer.ch/quaqua/guide/joptionpane.html JOptionPane pane = new JOptionPane(_("<html> " + "<head> <style type=\"text/css\">" + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }" + "</style> </head>" + "<b>Do you want to save changes to this sketch<BR>" + " before closing?</b>" + "<p>If you don't save, your changes will be lost."), JOptionPane.QUESTION_MESSAGE); String[] options = new String[] { _("Save"), _("Cancel"), _("Don't Save") }; pane.setOptions(options); // highlight the safest option ala apple hig pane.setInitialValue(options[0]); // on macosx, setting the destructive property places this option // away from the others at the lefthand side pane.putClientProperty("Quaqua.OptionPane.destructiveOption", new Integer(2)); JDialog dialog = pane.createDialog(this, null); dialog.setVisible(true); Object result = pane.getValue(); if (result == options[0]) { // save (and close/quit) return handleSave(true); } else if (result == options[2]) { // don't save (still close/quit) return true; } else { // cancel? return false; } } }