List of usage examples for javax.swing JOptionPane YES_NO_OPTION
int YES_NO_OPTION
To view the source code for javax.swing JOptionPane YES_NO_OPTION.
Click Source Link
showConfirmDialog
. From source file:Main.java
public static boolean confirmationPrompt(String msg, String title, Component parent) { Object[] options = { "Yes", "No" }; int n = JOptionPane.showOptionDialog(parent, msg, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (n == 0) { return true; } else {/*from ww w . j a v a 2 s. c om*/ return false; } }
From source file:Main.java
public static boolean confirmOverwrite(Component comp, File file) { if (file.exists()) { int decision = JOptionPane.showConfirmDialog(comp, file.getName() + " exists. Overwrite?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (decision == JOptionPane.NO_OPTION) { return false; }/* w w w . ja v a 2 s .com*/ } return true; }
From source file:Main.java
public static boolean showConfirm(String message) { return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, message, "Warning", JOptionPane.YES_NO_OPTION); }
From source file:Main.java
/** * Displays a yes/no question to the user. * //from ww w . j a va 2s .c o m * @param parent the parent <code>Component</code> * @param message the message to display * @return <code>true</code> if the user pressed 'yes' */ public static boolean displayYesNoPrompt(Component parent, String message) { return (JOptionPane.YES_OPTION == JOptionPane.showOptionDialog(parent, message, null, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null)); }
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
/** * Show a dialog that asks the user if a certain file should be overwritten. Nothing * will happen if the given file does not exist. * @param parent/*from w w w . j a v a 2s . c om*/ * @param file File to be overwritten. * @return {@code true} if the user confirms or if the file does not exist. */ public static boolean confirmFileWriting(Component parent, File file) { if (!file.exists()) return true; return JOptionPane.showConfirmDialog(parent, "The file '" + file.getName() + "' does already exist. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; }
From source file:Main.java
/** * Shows a confirm dialog./* w w w . j a va 2 s.com*/ * * @param c * the parent component. * @param msg * the message to display. * @param messageType * the type of message to display. * @return an int indicating the option selected by the user. */ public static int showConfirmDialog(Component c, String msg, int messageType) { return JOptionPane.showConfirmDialog(JOptionPane.getFrameForComponent(c), msg, UIManager.getString("OptionPane.confirmDialogTitle"), JOptionPane.YES_NO_OPTION, messageType); }
From source file:Main.java
/** * Mostra uma caixa de menssagem para que seja ensirido um valor. * @param frame//from ww w . ja v a 2 s.c om * @param texto * @param title * @param valorInicial * @param type * @return * @author Thiago Benega * @since 13/04/2009 */ public static String showTextboxDialog(javax.swing.JFrame frame, String texto, String title, String valorInicial, int type) { Object txt = null; JDialog jDialog = new JDialog(); jDialog.setTitle(title); jDialog.setFocusableWindowState(true); if (frame != null) { frame.setExtendedState(Frame.ICONIFIED); frame.pack(); frame.setExtendedState(Frame.MAXIMIZED_BOTH); } switch (type) { case JOptionPane.OK_CANCEL_OPTION: txt = JOptionPane.showInputDialog(jDialog, texto, title, type, null, null, valorInicial);//.toString(); break; case JOptionPane.YES_NO_OPTION: txt = JOptionPane.showConfirmDialog(jDialog, texto, title, type, JOptionPane.INFORMATION_MESSAGE); break; default: JOptionPane.showMessageDialog(jDialog, texto, title, type); break; } jDialog = null; return txt != null ? txt.toString() : null; }
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 www .jav a 2 s . c om*/ 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
public Main() { setSize(200, 200);//from ww w . ja v a 2 s. c om 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); } } }); }