- Using the showConfirmDialog static method to ask for user confirmation.
- This method displays a dialog with buttons on it, such as a Yes button, a No button, a Cancel button, or an OK button.
- You can select which buttons to appear or you can create your own buttons.
- Upon the user clicking a button, JOptionPane returns one of the following predefined ints:
- JOptionPane.YES_OPTION
- JOptionPane.NO_OPTION
- JOptionPane.CANCEL_OPTION
- JOptionPane.OK_OPTION
If the user closes a JOptionPane by clicking the close button at the top right hand corner of the dialog, the JOptionPane.CLOSED_OPTION int is returned.
The showConfirmDialog method has four overloads whose signatures are as follows.
public static int showConfirmDialog (java.awt.Component parent, java.lang.Object message)
public static int showConfirmDialog (java.awt.Component parent, java.lang.Object message, java.lang.String title, int optionType)
public static int showConfirmDialog (java.awt.Component parent, java.lang.Object message, java.lang.String title, int optionType, int messageType)
public static int showConfirmDialog (java.awt.Component parent, java.lang.Object message, java.lang.String title, int optionType, int messageType, Icon icon)
The optionType argument specifies the buttons that will be displayed. The possible values are as follows:
JOptionPane1.YES_NO_OPTION, which causes the Yes and No button to be displayed.
JOptionPane.YES_NO_CANCEL_OPTION, which causes the Yes, No, and Cancel buttons to be displayed.
If the first overload is used where there is no argument optionType is required, JOptionPane.YES_NO_CANCEL_OPTION is assumed.