Java JButton Settings askYesNoQuestion(String dlgTitle, String question, Component parent, Object[] buttonTittle)

Here you can find the source of askYesNoQuestion(String dlgTitle, String question, Component parent, Object[] buttonTittle)

Description

Shows a yes and no dialog with a specified question

License

Open Source License

Parameter

Parameter Description
dlgTitle -- the title of the dialog window
question -- the question to ask
parent -- the parent component
buttonTittle -- an string array of length 2 containing for the button. Its 1st elemtn will replace the ok and its seond element will replace the cancel

Return

true for a klick on yes otherwise false.

Declaration

public static boolean askYesNoQuestion(String dlgTitle, String question, Component parent,
        Object[] buttonTittle) 

Method Source Code


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

import java.awt.Component;

import javax.swing.JOptionPane;

public class Main {
    /**/*from   w  w  w  .j  a v  a 2s .com*/
     * Shows a yes and no dialog with a specified question
     * 
     * @param dlgTitle -- the title of the dialog window
     * @param question -- the question to ask
     * @param parent -- the parent component
     * @param buttonTittle -- an string array of length 2 containing
     *         for the button. Its 1st elemtn will replace the ok and 
     *          its seond element will replace the cancel            
     * @return true for a klick on yes otherwise false.
     */
    public static boolean askYesNoQuestion(String dlgTitle, String question, Component parent,
            Object[] buttonTittle) {
        Object[] options = { "Yes", "No" };
        if (buttonTittle != null) {
            if (buttonTittle.length == 2) {
                options[0] = buttonTittle[0];
                options[1] = buttonTittle[1];
            }
        }
        int n = JOptionPane.showOptionDialog(parent, question, dlgTitle, JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, //don't use a custom Icon
                options, //the titles of buttons
                options[0]); //default button title
        return (n == JOptionPane.YES_OPTION);
    }
}

Related

  1. addButtonToPanel(JPanel panel, Object constraints, String text)
  2. addMiddleButtonDragSupport(Component targetComponent)
  3. addRadioButton(JPanel buttonPanel, ButtonGroup group, String buttonName, boolean selected, ActionListener listener)
  4. addToButtonGroup(ButtonGroup bg, T button)
  5. applyDefaultProperties(final Button comp)
  6. buttonGroup(AbstractButton b1, AbstractButton b2)
  7. buttonGroup(JToggleButton b1, JToggleButton b2)
  8. clickButton(final Window window, final String buttonText)
  9. configureOKAndCancelButtons(JPanel panel, Action ok, Action cancel)