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

voidexcMsg(String msg, Throwable t)
Exception message dialog.
msg += "\n" + "Throwable: " + t + "\n" + t.getMessage();
JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.ERROR_MESSAGE);
System.out.println(msg);
voidexibeMsg(String msg, int tipoMsg)
exibe Msg
JOptionPane.showMessageDialog(framePrincipal, msg, tituloJanelaMsg, tipoMsg);
IcongetIconForType(int messageType)
get Icon For Type
if (messageType < 0 || messageType > 3) {
    return null;
switch (messageType) {
case JOptionPane.ERROR_MESSAGE:
    return UIManager.getIcon("OptionPane.errorIcon");
case JOptionPane.INFORMATION_MESSAGE:
    return UIManager.getIcon("OptionPane.informationIcon");
...
StringgetInput(String msg, String defaultInput)
get Input
String input = (String) JOptionPane.showInputDialog(msg, defaultInput);
return input;
intgetInt(String message, int min, int max, Integer initialValue)
get Int
Integer i = null;
while (i == null) {
    String s = JOptionPane.showInputDialog(message + " (" + min + " to " + max + ")", initialValue);
    try {
        i = Integer.parseInt(s);
    } catch (Exception e) {
return i;
intgetIntegerFromImput(String message, int min, int max)
get Integer From Imput
int num = 0;
JOptionPane optPane = new JOptionPane(message + " - Insert integer value: [" + min + "," + max + "]",
        JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
optPane.setWantsInput(true);
boolean isOk = false;
while (!isOk) {
    try {
        JDialog d = optPane.createDialog(null, "Input Value");
...
intgetIntegerInput(String message)
get Integer Input
int input = 0;
while (true) {
    boolean check = true;
    try {
        input = Integer.parseInt(JOptionPane.showInputDialog(null, message, ""));
    } catch (NumberFormatException e) {
        check = false;
    if (check == true)
        break;
return input;
IcongetJOptionPaneIcon(int jOptionPaneMessageType)
Get the icon used in the JOptionPane to signify its message type.
Integer messageTypeInteger = new Integer(jOptionPaneMessageType);
Icon icon = jOptionPaneMessageTypeToIconMap.get(messageTypeInteger);
if (icon == null) {
    OptionPaneUI ui = (new JOptionPane()).getUI();
    if (!(ui instanceof BasicOptionPaneUI)) {
        ui = new BasicOptionPaneUI();
        JOptionPane optionPane = new JOptionPane();
        optionPane.setUI(ui);
...
StringgetPassword(String message)
get Password
JPasswordField passwordField = new JPasswordField();
JOptionPane.showConfirmDialog(null, passwordField, message, JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.PLAIN_MESSAGE);
return new String(passwordField.getPassword());
StringgetString(Component component, String message)
get String
String value = JOptionPane.showInputDialog(component, message);
return value;