Example usage for javax.swing JOptionPane YES_NO_CANCEL_OPTION

List of usage examples for javax.swing JOptionPane YES_NO_CANCEL_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane YES_NO_CANCEL_OPTION.

Prototype

int YES_NO_CANCEL_OPTION

To view the source code for javax.swing JOptionPane YES_NO_CANCEL_OPTION.

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:Main.java

public static void main(String[] args) {
    int response = JOptionPane.showConfirmDialog(null, "Save the file?", "Confirm  Save  Changes",
            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);

    switch (response) {
    case JOptionPane.YES_OPTION:
        System.out.println("yes");
        break;/*from www.  ja  v a 2  s  . co  m*/
    case JOptionPane.NO_OPTION:
        System.out.println("no");
        break;
    case JOptionPane.CANCEL_OPTION:
        System.out.println("cancel");
        break;
    case JOptionPane.CLOSED_OPTION:
        System.out.println("closed.");
        break;
    default:
        System.out.println("something else");
    }

}

From source file:Main.java

public static void main(String[] args) {
    Object[] options1 = { "Try This Number", "Choose A Random Number", "Quit" };

    JPanel panel = new JPanel();
    panel.add(new JLabel("Enter number between 0 and 1000"));
    JTextField textField = new JTextField(10);
    panel.add(textField);/*from   w ww.  j  a  va  2  s .  c  o m*/

    int result = JOptionPane.showOptionDialog(null, panel, "Enter a Number", JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE, null, options1, null);
    if (result == JOptionPane.YES_OPTION) {
        JOptionPane.showMessageDialog(null, textField.getText());
    }
}

From source file:MainClass.java

public static void main(final String args[]) {
    UIManager.put("OptionPane.cancelButtonText", "Annuler");
    UIManager.put("OptionPane.noButtonText", "Non");
    UIManager.put("OptionPane.okButtonText", "D'accord");
    UIManager.put("OptionPane.yesButtonText", "Oui");

    int result = JOptionPane.showConfirmDialog(new JFrame(), "Est-ce que vous avez 18 ans ou plus?",
            "Choisisez une option", JOptionPane.YES_NO_CANCEL_OPTION);
    if (result == JOptionPane.YES_OPTION) {
        System.out.println("Yes");
    } else if (result == JOptionPane.NO_OPTION) {
        System.out.println("No");
    } else if (result == JOptionPane.CANCEL_OPTION) {
        System.out.println("Cancel");
    } else if (result == JOptionPane.CLOSED_OPTION) {
        System.out.println("Closed");
    }/*from w  ww.j  a v a  2 s  .  c  o  m*/
}

From source file:JOptionPaneDemonstrationLocalized.java

public static void main(String[] argv) {

        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font unicodeFont = new Font("LucidaSans", Font.PLAIN, 12);

        ResourceBundle bundle = ResourceBundle.getBundle("JOptionPaneResources", Locale.getDefault());

        String[] textMessages = new String[3];
        textMessages[0] = bundle.getString("Yes");
        textMessages[1] = bundle.getString("No");
        textMessages[2] = bundle.getString("Cancel");

        JOptionPane jop = new JOptionPane(bundle.getString("MessageText"), JOptionPane.ERROR_MESSAGE,
                JOptionPane.YES_NO_CANCEL_OPTION, null, textMessages);
        JDialog jopDialog = jop.createDialog(null, bundle.getString("TitleText"));
        jop.setFont(unicodeFont);/*from  w w  w .j av a  2s  .  c o m*/
        jopDialog.setVisible(true);
        Object userSelection = jop.getValue();
    }

From source file:Main.java

public static int yesnocancel(String theMessage) {
    int result = JOptionPane.showConfirmDialog((Component) null, theMessage, "alert",
            JOptionPane.YES_NO_CANCEL_OPTION);
    return result;
}

From source file:Main.java

public static int showReplaceExistingFileConfirmDialog(Component parentComponent, File file) {
    return JOptionPane.showConfirmDialog(parentComponent,
            "Do you want to replace the existing file " + file + " ?", "Warning",
            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
}

From source file:Main.java

static JOptionPane createOptionPane(String message, int type) {
    JOptionPane pane = new JOptionPane(message, type);

    if (type == JOptionPane.QUESTION_MESSAGE) {

        pane.setOptionType(JOptionPane.YES_NO_CANCEL_OPTION);
    }/*  w  ww  .j a  v  a 2s.co m*/
    return pane;
}

From source file:au.org.ala.delta.ui.MessageDialogHelper.java

/**
 * Uses JOptionPane.showInputDialog to display the supplied (multi-line) message and return the
 * user selection./*ww w .j  av  a 2  s.  c om*/
 * @param parent the parent component used to display the JOptionPane.
 * @param title the title for the option pane.
 * @param text the message text to display on the option pane.  Multi-line messages should 
 * use the "\n" character.
 * @param numColumns the column position to wrap the text at.
 * @return the value returned from the JOptionPane showConfirmDialog method (i.e the user selection)
 */
public static int showConfirmDialog(Component parent, String title, String text, int numColumns) {
    JTextArea messageDisplay = createMessageDisplay(text, numColumns);
    return JOptionPane.showConfirmDialog(parent, messageDisplay, title, JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);
}

From source file:rhinova.gui.dataentry.link.LinkDataEntryPanel.java

private void btnCreateActionPerformed(ActionEvent ev) {
    try {/*from   w w w  .j  av a2 s.  co m*/
        // test if the Tableable object can be created
        linkList.createTableable(getUserInputArray());

        // ask for confirmation
        int response = JOptionPane.showConfirmDialog(null, "Do you wish to create this Componenet?", "Confirm?",
                JOptionPane.YES_NO_CANCEL_OPTION);
        if (response == 0) {
            // create the object
            linkList.createAndAddNewInstance(getUserInputArray());
            JOptionPane.showMessageDialog(null, "Model Component Created", "Success",
                    JOptionPane.INFORMATION_MESSAGE);
        }
        // report exceptions to the user
    } catch (IncorrectDataType e) {
        EntityExceptionDialogs.onIncorrectDataType(e.getMessage());
    } catch (ConstraintViolatedException e) {
        EntityExceptionDialogs.onConstraintViolateException(e.getMessage());
    } catch (NullInputException e) {
        EntityExceptionDialogs.onNullInputException(e.getMessage());
    }
}

From source file:rhinova.gui.dataentry.reserve.ReserveDataEntryPanel.java

private void btnCreateReserveActionPerformed(ActionEvent ev) {
    try {//  w  ww .j  ava 2 s.  co  m
        // test if the Tableable object can be created
        reserveList.createTableable(getUserInputArray());

        // ask for confirmation
        int response = JOptionPane.showConfirmDialog(null, "Do you wish to create this Componenet?", "Confirm?",
                JOptionPane.YES_NO_CANCEL_OPTION);
        if (response == 0) {
            // create the object
            reserveList.createAndAddNewInstance(getUserInputArray());
            JOptionPane.showMessageDialog(null, "Model Component Created", "Success",
                    JOptionPane.INFORMATION_MESSAGE);
        }
        // report exceptions to the user
    } catch (IncorrectDataType e) {
        EntityExceptionDialogs.onIncorrectDataType(e.getMessage());
    } catch (ConstraintViolatedException e) {
        EntityExceptionDialogs.onConstraintViolateException(e.getMessage());
    } catch (NullInputException e) {
        EntityExceptionDialogs.onNullInputException(e.getMessage());
    }
}