null); pane.setInitialValue(null); pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
null); pane.setInitialValue(null); pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
null); pane.setInitialValue(null); pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
null); pane.setInitialValue(null); pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
public void show() { JOptionPane pane = new JOptionPane( "You have unsaved changes. Do you want to save them?", JOptionPane.QUESTION_MESSAGE); pane.setOptions(new Object[] {SAVE_AND_CLOSE, CLOSE_WITHOUT_SAVE, CANCEL}); pane.setInitialValue(SAVE_AND_CLOSE); pane.createDialog(parent, "Unsaved Changes").setVisible(true); Object selectedValue = pane.getValue(); result = CANCEL; if (SAVE_AND_CLOSE.equals(selectedValue)) { result = SAVE_AND_CLOSE; } else if (CLOSE_WITHOUT_SAVE.equals(selectedValue)) { result = CLOSE_WITHOUT_SAVE; } }
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException { JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, options, initialValue); pane.setInitialValue(initialValue); pane.setComponentOrientation(((parentComponent == null) ? getRootFrame() : parentComponent).getComponentOrientation()); int style = styleFromMessageType(messageType); JDialog dialog = pane.createDialog(parentComponent, title, style); pane.selectInitialValue(); dialog.show(); //..Result handling code }
private void showDialog(String name) { JCheckBox neverPromptAgainBox = new JCheckBox("Always delete without prompt."); Object message[] = { String.format("Are you sure you would like to delete the %s?", name), neverPromptAgainBox }; JOptionPane pane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE); pane.setOptions(new Object[]{ DELETE, "Cancel" }); pane.setInitialValue(DELETE); pane.createDialog(Application.getFrame(), "Confirm Delete").setVisible(true); shouldDelete = DELETE.equals(pane.getValue()); // If the user clicks "cancel" or window close button, we'll just ignore whatever's in the checkbox because // it's non-sensical. if (shouldDelete) { Preferences pref = Application.getInstance().getPreferencesNode( GeneralPreferences.class, ""); pref.putBoolean( GeneralPreferences.DELETE_PROMPT_PREFERENCE, neverPromptAgainBox.isSelected()); } }
private static String showOverwriteWarningDialog(File outputFile) { JOptionPane pane = new JOptionPane( format("File %s already exists. Overwrite?", outputFile), WARNING_MESSAGE); pane.setOptions(new String[]{OVERWRITE_YES, OVERWRITE_YES_ALL, OVERWRITE_NO, OVERWRITE_CANCEL}); pane.setInitialValue(OVERWRITE_NO); JDialog dialog = pane.createDialog(PixelitorWindow.getInstance(), "Warning"); dialog.setVisible(true); String value = (String) pane.getValue(); String answer; if (value == null) { // cancelled answer = OVERWRITE_CANCEL; } else { answer = value; } return answer; } }
final JOptionPane optionPane = new JOptionPane("What is your first name?", JOptionPane.QUESTION_MESSAGE); optionPane.setWantsInput(true); Action accept = new AbstractAction("OK") { private static final long serialVersionUID = 1; public void actionPerformed(ActionEvent event) { Object value = optionPane.getInputValue(); if (value != null && !value.toString().isEmpty()) { // This dismisses the JOptionPane dialog. optionPane.setValue(JOptionPane.OK_OPTION); } } }; Object acceptButton = new JButton(accept); optionPane.setOptions(new Object[] { acceptButton, "Cancel" }); optionPane.setInitialValue(acceptButton); // Waits until dialog is dismissed. optionPane.createDialog(null, "First Name").setVisible(true); if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(optionPane.getValue())) { // User canceled dialog. return; } String fn = optionPane.getInputValue().toString();
null); pane.setInitialValue(null); pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
null); pane.setInitialValue(null); pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
private void cancelIndexing() { String message = ""; message += "WARNING: Canceling indexing before completion will result in an" + "\n"; message += "incomplete index. Rebuilding of the index will be REQUIRED." + "\n\n"; message += "Are you sure you want to continue?" + "\n "; JOptionPane jOptionPane = new JOptionPane(message); jOptionPane.setMessageType(JOptionPane.WARNING_MESSAGE); String yes = "Yes"; String no = "No"; jOptionPane.setOptions(new String[] { yes, no }); Dialog d = jOptionPane.createDialog("WARNING"); jOptionPane.setInitialValue(no); d.setVisible(true); if (jOptionPane.getValue() != null && jOptionPane.getValue().equals(yes)) { this.cancelled = true; this.beginIndexingJButton.setEnabled(false); } }
pane.setInitialValue(createBtn); } else { pane.setOptions(new JButton[] { deleteBtn, copyBtn }); pane.setInitialValue(copyBtn);
Object[] options = {labels.getString("application.exit.saveOption"), labels.getString("application.exit.cancelOption"), labels.getString("application.exit.dontSaveOption")}; pane.setOptions(options); pane.setInitialValue(options[0]); pane.putClientProperty("Quaqua.OptionPane.destructiveOption", 2); JSheet.showSheet(pane, unsavedView.getComponent(), new SheetListener() { Object[] options = {labels.getString("application.exit.reviewChangesOption"), labels.getString("application.exit.cancelOption"), labels.getString("application.exit.discardChangesOption")}; pane.setOptions(options); pane.setInitialValue(options[0]); pane.putClientProperty( "Quaqua.OptionPane.destructiveOption", 2);
Object[] options = {labels.getString("application.exit.saveOption"), labels.getString("application.exit.cancelOption"), labels.getString("application.exit.dontSaveOption")}; pane.setOptions(options); pane.setInitialValue(options[0]); pane.putClientProperty("Quaqua.OptionPane.destructiveOption", 2); JSheet.showSheet(pane, unsavedView.getComponent(), new SheetListener() {
options, initialValue); pane.setInitialValue(initialValue); pane.setComponentOrientation(((parentComponent == null) ? JOptionPane.getRootFrame() : parentComponent).getComponentOrientation());
}; pane.setOptions(options); pane.setInitialValue(options[0]); pane.putClientProperty("Quaqua.OptionPane.destructiveOption", 2); JSheet.showSheet(pane, v.getComponent(), new SheetListener() {