Java Utililty Methods JOptionPane Message

List of utility methods to do JOptionPane Message

Description

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

Method

booleanqueryBoolean(String message)
Queries the User for a Boolean value.
int revan = JOptionPane.showConfirmDialog(null, message);
return (revan == JOptionPane.YES_OPTION);
doublequeryDouble(String message, double initialValue)
Queries the User for a Double values using Swing.
String input = JOptionPane.showInputDialog(message, "" + initialValue);
if (input == null)
    throw new Exception("Selection aborted");
return Double.parseDouble(input);
intqueryInt(String message, int initialValue)
Queries the User for an Integer value using Swing.
String input = JOptionPane.showInputDialog(message, "" + initialValue);
if (input == null)
    throw new Exception("Selection aborted");
return Integer.parseInt(input);
StringrequestPassword(String titulo, String msg)
request Password
JPanel panel = new JPanel();
JLabel label = new JLabel(msg);
JPasswordField pass = new JPasswordField(10);
panel.add(label);
panel.add(pass);
pass.requestFocusInWindow();
String[] options = new String[] { "OK", "Cancelar" };
int option = JOptionPane.showOptionDialog(null, panel, titulo, JOptionPane.NO_OPTION,
...
intselect(String[] selList, String msg)
select
JComboBox<String> box = new JComboBox<>(selList);
Object msgs[] = new Object[2];
msgs[0] = msg;
msgs[1] = box;
int result = JOptionPane.showOptionDialog(null, msgs, msg, JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.QUESTION_MESSAGE, null, null, null);
if (result == JOptionPane.CANCEL_OPTION)
    return -1;
...
Objectshow(String title, int type, Object message, Object[] options, Object initialOption)
Helper method for constructing an always-on-top modal dialog.
if (options == null) {
    options = new Object[] { "Ok" };
    initialOption = "Ok";
JOptionPane p = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, options, initialOption);
p.setInitialValue(initialOption);
JDialog d = p.createDialog(null, title);
p.selectInitialValue();
...
voidshowActionFailedWithExceptionMessage(final Component parent, final Exception ex)
show Action Failed With Exception Message
SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
        JOptionPane.showMessageDialog(parent,
                "Die Aktion konnten nicht abgeschlossen werden, da folgender Fehler auftrat:\n<HTML><I>"
                        + ex.getLocalizedMessage() + "</I></HTML>",
                "Aktion fehlgeschlagen", JOptionPane.ERROR_MESSAGE);
});
voidshowAlert(String message)
Uses the JOptionPane.showMessageDialog() method to display the specified alert message.
JOptionPane.showMessageDialog(null, message, "JFMI Alert", JOptionPane.INFORMATION_MESSAGE);
voidshowException(Component c, String message, Throwable t)
Utility method to display a popup with the provided message ant Throwable
if (t == null) {
    t = new Exception("Unknown Exception");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
t.printStackTrace(new PrintStream(baos));
if (message == null) {
    message = t.getClass().getName();
String stackTrace = baos.toString();
message += System.getProperty("line.separator") + stackTrace;
JOptionPane.showMessageDialog(c, message, "Error Message", JOptionPane.ERROR_MESSAGE);
voidshowException(String message, Exception ex)
Presents a modal dialog displaying the given message and information about the given exception.
ex.printStackTrace();
JOptionPane.showMessageDialog(null, message + "\n\n" + ex + "\n");