Example usage for javax.swing JOptionPane DEFAULT_OPTION

List of usage examples for javax.swing JOptionPane DEFAULT_OPTION

Introduction

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

Prototype

int DEFAULT_OPTION

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

Click Source Link

Document

Type meaning Look and Feel should not supply any options -- only use the options from the JOptionPane.

Usage

From source file:Main.java

public static void main(String[] args) {
    int option = JOptionPane.showOptionDialog(null, "Title", "Message", JOptionPane.DEFAULT_OPTION,
            JOptionPane.PLAIN_MESSAGE, null, State.values(), State.values()[0]);
    if (option == JOptionPane.CLOSED_OPTION) {
        System.out.println("user closed the JOptionPane without selecting");
    } else {//from   w w  w.  ja  va  2 s . co m
        State state = State.values()[option];
        doAction(state);
        System.out.println("code to do something based selected state");
    }
}

From source file:Main.java

public static void main(String... args) {
    JOptionPane optionPane = new JOptionPane("Its me", JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION,
            null, null, "Please ENTER your NAME here");
    optionPane.setWantsInput(true);// www  .ja  v  a2  s .  c o m
    JDialog dialog = optionPane.createDialog(null, "TEST");
    dialog.setLocation(10, 20);
    dialog.setVisible(true);
    System.out.println(optionPane.getInputValue());

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JOptionPane jop = new JOptionPane("Message", JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION);

    JDialog dialog = jop.createDialog("Dialog Title");

    Image image = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    dialog.setIconImage(image);/*from  w w w.  ja v a  2s .  c om*/
    dialog.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String[] weekdays = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
    final JComboBox<String> combo = new JComboBox<>(weekdays);

    String[] options = { "OK", "Cancel", "Help" };

    String title = "Title";
    int selection = JOptionPane.showOptionDialog(null, combo, title, JOptionPane.DEFAULT_OPTION,
            JOptionPane.PLAIN_MESSAGE, null, options, options[0]);

    if (selection > 0) {
        System.out.println("selection is: " + options[selection]);
    }//  w  w w. ja  v a2 s .  c  o  m

    Object weekday = combo.getSelectedItem();
    if (weekday != null) {
        System.out.println("weekday: " + weekday);
    }

}

From source file:Main.java

public static void main(String[] args) {
    JComponent parentComponent = null;
    Object message = "How  is JOptionPane?";
    String title = "JOptionPane Option  Dialog";
    int messageType = JOptionPane.INFORMATION_MESSAGE;
    Icon icon = null;/*  w  ww  .j  a  va 2s  .c om*/
    Object[] options = new String[] { "A", "B", "C" };
    Object initialOption = options[2];
    int response = JOptionPane.showOptionDialog(null, message, title, JOptionPane.DEFAULT_OPTION,
            JOptionPane.QUESTION_MESSAGE, icon, options, initialOption);
    switch (response) {
    case 0:
    case 1:
    case 2:
        System.out.println("we selected:" + options[response]);
        break;
    case JOptionPane.CLOSED_OPTION:
        System.out.println("we closed the   dialog box.");
        break;
    default:
        System.out.println("I don't know what  we  did.");
    }

}

From source file:NoButtonPopup.java

public static void main(String args[]) {

    JFrame frame = new JFrame("NoButton Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Ask");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Component source = (Component) actionEvent.getSource();
            int response = JOptionPane.showOptionDialog(source, "", "Empty?", JOptionPane.DEFAULT_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, new Object[] {}, null);
            System.out.println("Response: " + response);
        }//from  w w w  . java 2  s  . c o m
    };
    button.addActionListener(actionListener);
    Container contentPane = frame.getContentPane();
    contentPane.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:kevin.gvmsgarch.App.java

public static void main(String[] args) throws HttpException, IOException, ParserConfigurationException,
        SAXException, XPathExpressionException, JSONException, InterruptedException {
    System.out.println("Google Voice Message Archiver");
    System.out.println("Copyright (C) 2013 Kevin Carter");

    System.out.println("This program comes with ABSOLUTELY NO WARRANTY");
    System.out.println("This is free software, and you are welcome to redistribute it");
    System.out.println("under certain conditions. See the LICENSE file or");
    System.out.println("http://www.gnu.org/licenses/gpl-3.0.txt for details");
    try {//from   w  ww  .j  a  va  2s.com
        HttpClient c = new HttpClient();

        String userName = getUserName();
        String password = getPassword();

        int locationChosenIndex = JOptionPane.CLOSED_OPTION;
        if (password != null) {
            locationChosenIndex = JOptionPane.showOptionDialog(null, "Message source", "",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    Worker.ListLocation.values(), Worker.ListLocation.inbox);
        }
        if (locationChosenIndex != JOptionPane.CLOSED_OPTION) {
            int modeChosenIndex = 0;
            Worker.ArchiveMode modeChosen = null;
            Worker.ListLocation location = Worker.ListLocation.values()[locationChosenIndex];
            Worker.ArchiveMode[] availableModes = location.getAllowedModes();
            if (availableModes.length == 1) {
                modeChosen = availableModes[0];
            } else {
                modeChosenIndex = JOptionPane.showOptionDialog(null, "Operation mode", "",
                        JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, availableModes,
                        Worker.ArchiveMode.archive);
                if (modeChosenIndex != JOptionPane.CLOSED_OPTION) {
                    modeChosen = availableModes[modeChosenIndex];
                }
            }

            ContactFilter filter = null;
            if (modeChosenIndex != JOptionPane.CLOSED_OPTION
                    && locationChosenIndex != JOptionPane.CLOSED_OPTION) {
                filter = buildFilter();
            }

            if (modeChosenIndex != JOptionPane.CLOSED_OPTION && locationChosenIndex != JOptionPane.CLOSED_OPTION
                    && filter != null && areYouSure(modeChosen, location, filter)) {
                assert modeChosen != null : "ZOMG";
                String authToken = getToken(userName, password);
                String rnrse = getRnrse(authToken);

                final ProgressMonitor pm = new ProgressMonitor(null, "Working", "", 0,
                        App.parseMsgsLeft(extractInboxJson(authToken, location, 1)));
                pm.setMillisToDecideToPopup(0);
                pm.setMillisToPopup(0);

                Worker worker = new Worker(authToken, rnrse, pm, modeChosen, location, filter);
                worker.addPropertyChangeListener(new ProgressPropertyChangeListener(pm));
                pm.setProgress(0);
                worker.execute();
            }
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:Main.java

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

From source file:Main.java

private void displayGUI() {
    JOptionPane optionPane = new JOptionPane(getPanel(), JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION,
            null, new Object[] {}, null);
    dialog = optionPane.createDialog("import");
    dialog.setVisible(true);/*from w w  w  .ja  va2  s . c  om*/
}

From source file:Main.java

protected static void errorMessage(String errorMessage) {

    /**/*w  ww.  j  a va2s  . com*/
     * Display Jpanel Error messages any text Errors. Overloads
     * errorMessage(Exception exceptionMsg)
     */
    Object[] options = { "OK" };

    JOptionPane.showOptionDialog(null, errorMessage, messagerHeader, JOptionPane.DEFAULT_OPTION,
            JOptionPane.WARNING_MESSAGE, null, options, options[0]);

    // DatabaseManagerSwing.StatusMessage(READY_STATUS);
}