List of usage examples for javax.swing JOptionPane CLOSED_OPTION
int CLOSED_OPTION
To view the source code for javax.swing JOptionPane CLOSED_OPTION.
Click Source Link
CANCEL_OPTION
or NO_OPTION
. 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 {/* w w w . j a v a 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) { int result = JOptionPane.showConfirmDialog(null, "This is a test", "Test", JOptionPane.YES_NO_OPTION); System.out.println("result: " + result); switch (result) { case JOptionPane.YES_OPTION: System.out.println("Yes Pressed"); break;// w w w. ja v a2 s . com case JOptionPane.NO_OPTION: System.out.println("No Pressed"); break; case JOptionPane.CLOSED_OPTION: System.out.println("Dialog closed"); break; default: System.out.println("Default"); break; } }
From source file:Main.java
public static void main(String args[]) { int n = JOptionPane.showOptionDialog(new JFrame(), "Message", "Title", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Yes", "No" }, JOptionPane.YES_OPTION); if (n == JOptionPane.YES_OPTION) { System.out.println("Yes"); } else if (n == JOptionPane.NO_OPTION) { System.out.println("No"); } else if (n == JOptionPane.CLOSED_OPTION) { System.out.println("Closed by hitting the cross"); }/* w w w . jav a2 s. com*/ }
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;/* ww w . j a v a 2 s . c o 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:JOptionPaneTest2.java
public static void main(String[] args) { JDialog.setDefaultLookAndFeelDecorated(true); int response = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.NO_OPTION) { System.out.println("No button clicked"); } else if (response == JOptionPane.YES_OPTION) { System.out.println("Yes button clicked"); } else if (response == JOptionPane.CLOSED_OPTION) { System.out.println("JOptionPane closed"); }//from ww w .j ava 2 s . c o m }
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 w w .j a va2s .c o m 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:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(200, 200);//ww w. j a va 2 s.c o m frame.setVisible(true); JOptionPane.showMessageDialog(frame, "A"); JOptionPane.showMessageDialog(frame, "B", "message", JOptionPane.WARNING_MESSAGE); int result = JOptionPane.showConfirmDialog(null, "Remove now?"); switch (result) { case JOptionPane.YES_OPTION: System.out.println("Yes"); break; 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; } String name = JOptionPane.showInputDialog(null, "Please enter your name."); System.out.println(name); JTextField userField = new JTextField(); JPasswordField passField = new JPasswordField(); String message = "Please enter your user name and password."; result = JOptionPane.showOptionDialog(frame, new Object[] { message, userField, passField }, "Login", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) System.out.println(userField.getText() + " " + new String(passField.getPassword())); }
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 www.ja v a 2s .co m*/ }
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 w w. ja va 2s . co m*/ 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:GettingJOptionPaneSelectionDemo.java
public static int getSelection(JOptionPane optionPane) { int returnValue = JOptionPane.CLOSED_OPTION; Object selectedValue = optionPane.getValue(); if (selectedValue != null) { Object options[] = optionPane.getOptions(); if (options == null) { if (selectedValue instanceof Integer) { returnValue = ((Integer) selectedValue).intValue(); }/* w w w . j a va 2 s. c om*/ } else { for (int i = 0, n = options.length; i < n; i++) { if (options[i].equals(selectedValue)) { returnValue = i; break; // out of for loop } } } } return returnValue; }