Java JOptionPane Confirmation confirmDialog(Component owner, String title, String message)

Here you can find the source of confirmDialog(Component owner, String title, String message)

Description

Use this instead of JOptionPane.showMessageDialog(..., JOptionPane.QUESTION_MESSAGE) Default ModalityType.DOCUMENT_MODAL

License

Open Source License

Parameter

Parameter Description
owner a parameter
title a parameter
message a parameter

Return

, , or

Declaration

public static int confirmDialog(Component owner, String title, String message) 

Method Source Code

//package com.java2s;
/*// www  .j a  v  a 2  s . co m
 * Copyright (c) 2004-2013 Universidade do Porto - Faculdade de Engenharia
 * Laborat?rio de Sistemas e Tecnologia Subaqu?tica (LSTS)
 * All rights reserved.
 * Rua Dr. Roberto Frias s/n, sala I203, 4200-465 Porto, Portugal
 *
 * This file is part of Neptus, Command and Control Framework.
 *
 * Commercial Licence Usage
 * Licencees holding valid commercial Neptus licences may use this file
 * in accordance with the commercial licence agreement provided with the
 * Software or, alternatively, in accordance with the terms contained in a
 * written agreement between you and Universidade do Porto. For licensing
 * terms, conditions, and further information contact lsts@fe.up.pt.
 *
 * European Union Public Licence - EUPL v.1.1 Usage
 * Alternatively, this file may be used under the terms of the EUPL,
 * Version 1.1 only (the "Licence"), appearing in the file LICENCE.md
 * included in the packaging of this file. You may not use this work
 * except in compliance with the Licence. Unless required by applicable
 * law or agreed to in writing, software distributed under the Licence is
 * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the Licence for the specific
 * language governing permissions and limitations at
 * https://www.lsts.pt/neptus/licence.
 *
 * For more information please see <http://lsts.fe.up.pt/neptus>.
 *
 * Author: 
 * 24/Fev/2005
 */

import java.awt.Component;
import java.awt.Dialog.ModalityType;

import javax.swing.JDialog;

import javax.swing.JOptionPane;

public class Main {
    /**
     * Use this instead of JOptionPane.showMessageDialog(..., JOptionPane.QUESTION_MESSAGE)
     * Default ModalityType.DOCUMENT_MODAL
     * @param owner
     * @param title
     * @param message
     * @return {@link JOptionPane#YES_OPTION}, {@link JOptionPane#NO_OPTION}, or {@link JOptionPane#CLOSED_OPTION}
     */
    public static int confirmDialog(Component owner, String title, String message) {
        return confirmDialog(owner, title, message, ModalityType.DOCUMENT_MODAL);
    }

    /**
     * Use this instead of JOptionPane.showMessageDialog(..., JOptionPane.QUESTION_MESSAGE)
     * @param owner
     * @param title
     * @param message
     * @return {@link JOptionPane#YES_OPTION}, {@link JOptionPane#NO_OPTION}, or {@link JOptionPane#CLOSED_OPTION}
     */
    public static int confirmDialog(Component owner, String title, String message, ModalityType modalityType) {
        // int response = JOptionPane.showConfirmDialog(owner, message, title, JOptionPane.YES_NO_OPTION);
        // return response; // == JOptionPane.YES_OPTION;

        JOptionPane jop = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
        JDialog dialog = jop.createDialog(owner, title);
        dialog.setModalityType(modalityType);
        dialog.setVisible(true);
        Object selectedValue = jop.getValue();
        if (selectedValue == null)
            return JOptionPane.CLOSED_OPTION;
        if (selectedValue instanceof Integer)
            return ((Integer) selectedValue).intValue();
        return JOptionPane.CLOSED_OPTION;
    }
}

Related

  1. confirmAction(Component comp, String title, String msg)
  2. confirmarEliminar(Component component, String titulo, String mensaje)
  3. confirmationBox(String msg, String title)
  4. confirmationPrompt(String msg, String title, Component parent)
  5. confirmChangeReference(boolean isChangingProject)
  6. confirmDialog(String msg, String title)
  7. confirmDialogWorker(Component owner, String title, String message, ModalityType modalityType, int option)
  8. ConfirmMessage(String strMsg)
  9. confirmUserChoiceWithCustomOptions(final Component sourceComponent, final String question, final String defaultOption, final String... options)