Java JOptionPane Confirmation showConfirmDialog(String message)

Here you can find the source of showConfirmDialog(String message)

Description

Shows a confirm dialog with "Yes", "No", and "Cancel" buttons.

License

Open Source License

Parameter

Parameter Description
message The message to appear in the dialog.

Return

an int representing the selected value. This value will be: JOptionPane. This can be any of the following: YES_OPTION - if the "Yes" option was pressed. NO_OPTION - if the "No" option was pressed. CANCEL_OPTION - if the "Cancel" option was pressed. DIALOG_CLOSED - if the user closed the dialog.

Declaration

public static int showConfirmDialog(String message) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;

public class Main {
    private static JFrame frame = null;

    /**/*  www  .  ja va 2  s. com*/
     * Shows a confirm dialog with "Yes", "No", and "Cancel" buttons.
     *
     * @param message The message to appear in the dialog.
     * @return an int representing the selected value. This value will be:
     *         JOptionPane. This can be any of the following:
     *         YES_OPTION - if the "Yes" option was pressed.
     *         NO_OPTION - if the "No" option was pressed.
     *         CANCEL_OPTION - if the "Cancel" option was pressed.
     *         DIALOG_CLOSED - if the user closed the dialog.
     */
    public static int showConfirmDialog(String message) {
        return JOptionPane.showConfirmDialog(frame, message);
    }

    /**
     * Shows a confirm dialog with the specified buttons.
     * <p/>
     * This dialog will keep focus until the user closes it.
     *
     * @param message The message to be displayed in the dialog.
     * @param type    The type of window. This can be any of the following:
     *                YES_NO_CANCEL - for a dialog that has "Yes", "No", and "Cancel" options.
     *                YES_NO - for a dialog that has "Yes" and "No" options.
     *                OK_CANCEL - for a dialog that has "Ok" and "Cancel" options.
     * @return an int specifying what option was pressed. This can be any of the following:
     *         YES_OPTION - if the "Yes" option was pressed.
     *         NO_OPTION - if the "No" option was pressed.
     *         OK_OPTION - if the "Ok" option was pressed.
     *         CANCEL_OPTION - if the "Cancel" option was pressed.
     *         DIALOG_CLOSED - if the dialog was closed without an option being pressed.
     */
    public static int showConfirmDialog(String message, int type) {
        return JOptionPane.showConfirmDialog(frame, message, "Confirm", type);
    }
}

Related

  1. showConfirmationDialog(Component parent, String message)
  2. showConfirmationDialog(String title, String question)
  3. showConfirmDialog(Component parentComponent, Object message, String title)
  4. showConfirmDialog(final Component parent, final String title, final String message)
  5. showConfirmDialog(final Component parentComponent, final String message)
  6. showConfirmDialog(String title, String message)
  7. showConfirmMessage(String message, Component component)
  8. showQuestionConfirmBox(Component pParent, String pMessage, String pTitle, String pLeftOption, String pRightOption)
  9. showReplaceExistingFileConfirmDialog(Component parentComponent, File file)