Java Utililty Methods JOptionPane Confirmation

List of utility methods to do JOptionPane Confirmation

Description

The list of methods to do JOptionPane Confirmation are organized into topic(s).

Method

booleanconfirmarEliminar(Component component, String titulo, String mensaje)
confirmar Eliminar
int botones = JOptionPane.CANCEL_OPTION;
int respuesta = JOptionPane.showConfirmDialog(component, mensaje, titulo, botones,
        JOptionPane.QUESTION_MESSAGE);
if (respuesta == JOptionPane.YES_OPTION) {
    return true;
return false;
booleanconfirmationBox(String msg, String title)
confirmation Box
int result = JOptionPane.showConfirmDialog(null, msg, title, JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
    return true;
} else {
    return false;
booleanconfirmationPrompt(String msg, String title, Component parent)
confirmation Prompt
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 {
    return false;
booleanconfirmChangeReference(boolean isChangingProject)
confirm Change Reference
int result = JOptionPane.showConfirmDialog(getFrontWindow(),
        "<HTML>Changing the " + (isChangingProject ? "project" : "reference")
                + " will remove current filters.<BR>Are you sure you want to do this?</HTML>",
        "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
return result == JOptionPane.YES_OPTION;
intconfirmDialog(Component owner, String title, String message)
Use this instead of JOptionPane.showMessageDialog(..., JOptionPane.QUESTION_MESSAGE) Default ModalityType.DOCUMENT_MODAL
return confirmDialog(owner, title, message, ModalityType.DOCUMENT_MODAL);
booleanconfirmDialog(String msg, String title)
confirm Dialog
return JOptionPane.showConfirmDialog(null, msg, title,
        JOptionPane.YES_NO_OPTION) == JFileChooser.APPROVE_OPTION;
intconfirmDialogWorker(Component owner, String title, String message, ModalityType modalityType, int option)
confirm Dialog Worker
JOptionPane jop = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, 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)
...
booleanConfirmMessage(String strMsg)
Confirm Message
if ((JOptionPane.showConfirmDialog((Component) null, strMsg, "Peticion",
        JOptionPane.OK_CANCEL_OPTION)) == JOptionPane.OK_OPTION)
    return true;
else
    return false;
intconfirmUserChoiceWithCustomOptions(final Component sourceComponent, final String question, final String defaultOption, final String... options)
confirm User Choice With Custom Options
final int selectedOption = JOptionPane.showOptionDialog(sourceComponent, question, "CONFIRM",
        JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, defaultOption);
return selectedOption;
booleanconfirmWindow(String title, String message)
confirm Window
int result = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.OK_CANCEL_OPTION);
return result != JOptionPane.CANCEL_OPTION;