Java JOptionPane Error askForAStringInArray(String question, String header, Object[] options, String errorMessage, String errorHeader)

Here you can find the source of askForAStringInArray(String question, String header, Object[] options, String errorMessage, String errorHeader)

Description

Ask in a swing gui for something in array

License

Open Source License

Parameter

Parameter Description
question the question to ask
header the header of the box
options the options the user can chose from
errorMessage the error message when something is wrong
errorHeader the error message header box when something is wrong

Return

the value found

Declaration

public static int askForAStringInArray(String question, String header, Object[] options, String errorMessage,
        String errorHeader) 

Method Source Code


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

import javax.swing.*;

public class Main {
    /**/*from  w  ww.  jav a 2s.c  o m*/
     * Ask in a swing gui for something in array
     * @param question the question to ask
     * @param header the header of the box
     * @param options the options the user can chose from
     * @param errorMessage the error message when something is wrong
     * @param errorHeader the error message header box when something is wrong
     * @return the value found
     */
    public static int askForAStringInArray(String question, String header, Object[] options, String errorMessage,
            String errorHeader) {
        int res = JOptionPane.CLOSED_OPTION;

        while (res == JOptionPane.CLOSED_OPTION) {
            res = JOptionPane.showOptionDialog(null, question, header, JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, //do not use a custom Icon
                    options, //the titles of buttons
                    options[0]); //default button title
            if (res == JOptionPane.CLOSED_OPTION) {
                JOptionPane.showMessageDialog(null, errorMessage, errorHeader, JOptionPane.ERROR_MESSAGE);
            }
        }
        return res;
    }
}

Related

  1. alertValidationError(final Component sourceComponent, final String message)
  2. askForAStringInArrayReturning(String question, String header, T[] options, String errorMessage, String errorHeader)
  3. contChoose(final Component parent, final String title, final String message, final String noContMsg, boolean cont, boolean error)
  4. createAndShowErrorPanel(String title, Map messages)
  5. displayError(Component parent, String title, String message)