Example usage for javax.swing JOptionPane QUESTION_MESSAGE

List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE

Introduction

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

Prototype

int QUESTION_MESSAGE

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

Click Source Link

Document

Used for questions.

Usage

From source file:Main.java

public static boolean askUser(Component parent, String question) {
    int i = JOptionPane.showOptionDialog(parent, question, "Question", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, null, null);
    return i == JOptionPane.YES_OPTION;
}

From source file:Main.java

public static int select(String[] selList, String msg) {
    JComboBox<String> box = new JComboBox<>(selList);
    Object msgs[] = new Object[2];
    msgs[0] = msg;/*from  w w  w . j a v  a 2s  . c o  m*/
    msgs[1] = box;
    int result = JOptionPane.showOptionDialog(null, msgs, msg, JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, null, null);
    if (result == JOptionPane.CANCEL_OPTION)
        return -1;
    return box.getSelectedIndex();
}

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

/**
 * Displays a confirmation window asking a user a yes or no question.
 * @param message   the message to show.
 * @param parent   Parent component of this dialog.
 * @return         true if "yes" was clicked. false otherwise.
 *//*from w w w  . j  a  v  a  2s.  c o m*/
public static boolean yesTo(String message, Component parent) {
    int c = JOptionPane.showConfirmDialog(parent, message, "Confirm", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    boolean out = c == JOptionPane.YES_OPTION;
    return out;
}

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  w  w. j av a 2 s  .c  om*/
    return pane;
}

From source file:Main.java

public Main() {
    setSize(200, 200);/*from ww w .j  a v a 2  s.  c o  m*/
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            Object[] options = { "Quit, My Computing Fellow", "No, I want to Work more" };

            int answer = JOptionPane.showOptionDialog(Main.this, "What would you like to do? ", "Quit:Continue",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            if (answer == JOptionPane.YES_OPTION) {
                System.exit(0);
            }
        }
    });
}

From source file:Main.java

/**
 * Shows a simple yes/no confirmation dialog, with the "no" option selected by default. This method exists
 * only because there's apparently no easy way to accomplish that with JOptionPane's static helper
 * methods.//www.  j a  v a  2s  .  c  o m
 * 
 * @param parentComponent
 * @param message
 * @param title
 * @see JOptionPane#showConfirmDialog(Component, Object, String, int)
 */
public static int showConfirmDialog(Component parentComponent, Object message, String title) {
    String[] options = { "Yes", "No" };
    return JOptionPane.showOptionDialog(parentComponent, message, title, JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
}

From source file:Main.java

public Main() {
    options.add(createOptionPane("Plain Message", JOptionPane.PLAIN_MESSAGE));
    options.add(createOptionPane("Error Message", JOptionPane.ERROR_MESSAGE));
    options.add(createOptionPane("Information Message", JOptionPane.INFORMATION_MESSAGE));
    options.add(createOptionPane("Warning Message", JOptionPane.WARNING_MESSAGE));
    options.add(createOptionPane("Want to do something?", JOptionPane.QUESTION_MESSAGE));
    items = new Object[] { "First", "Second", "Third" };
    JComboBox choiceCombo = new JComboBox(items);
    options.add(new JOptionPane(choiceCombo, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION),
            "Question Message");
    JFrame frame = new JFrame("JOptionPane'Options");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(options, BorderLayout.CENTER);
    frame.pack();// w w w .  ja  va2 s . com
    frame.setVisible(true);
}

From source file:Main.java

/**Prompt the user to choose between two courses of action.
 @return true if the user chose the default course of action,
   false if the alternate course was chosen of the prompt closed.*/
public static boolean prompt2(Component parent, String question, String title, String defaultActionText,
        String alternateActionText) {
    Object[] values = new Object[] { defaultActionText, alternateActionText };

    int choice = JOptionPane.showOptionDialog(parent, question, title, JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, values, values[0]);

    return choice == JOptionPane.YES_OPTION;
}

From source file:Main.java

public void launchDialog() {
    JButton findButton = new JButton("Find");
    findButton.addActionListener(e -> {
        int start = text.getText().indexOf("is");
        int end = start + "is".length();
        if (start != -1) {
            text.requestFocus();//from   w  ww  . j  a va  2s . com
            text.select(start, end);
        }
    });
    JButton cancelButton = new JButton("Cancel");

    JOptionPane optionPane = new JOptionPane("Do you understand?", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION, null, new Object[] { findButton, cancelButton });

    JDialog dialog = new JDialog(frame, "Click a button", false);
    cancelButton.addActionListener(e -> dialog.setVisible(false));
    dialog.setContentPane(optionPane);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.setLocation(100, 100);
    dialog.pack();
    dialog.setVisible(true);
}