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

voidshowExceptionMessage(Component parent, Throwable t)
Shows a message box with exception details.
StringBuilder sb = new StringBuilder();
sb.append("An unexpected error occured during the execution of the requested task.\n");
sb.append("The error data can be seen below:\n\n");
sb.append(t.getLocalizedMessage());
sb.append(t.toString()).append("\n");
sb.append("Stack Trace:\n");
for (StackTraceElement e : t.getStackTrace()) {
    sb.append(e.toString()).append("\n");
...
voidshowExceptionMessage(Component parentComponent, Exception exception)
Show an Exception dialogue.
StringWriter stringWriter = new StringWriter();
exception.printStackTrace(new PrintWriter(stringWriter));
JLabel message = new JLabel(exception.getMessage());
message.setBorder(BorderFactory.createEmptyBorder(3, 0, 10, 0));
JTextArea text = new JTextArea();
text.setEditable(false);
text.setFont(UIManager.getFont("Label.font"));
text.setText(stringWriter.toString());
...
booleanshowExceptionMessage(Exception e)
show Exception Message
try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception el) {
    JOptionPane.showMessageDialog(new JDialog(), e.getMessage());
    el.printStackTrace();
JOptionPane.showMessageDialog(new JDialog(), e.getMessage());
e.printStackTrace();
...
voidshowExceptionMessage(Exception e)
show Exception Message
String msg = "An exception has occurred.\n\n" + e.toString()
        + "\n\nIf problems persist, please contact your local administrator.";
e.printStackTrace(System.out);
JOptionPane.showMessageDialog(mainComponent, msg, "Exception", JOptionPane.ERROR_MESSAGE);
StringshowInput(Component parent, String message, String initValue)
Show a input dialog.
String input = null;
input = JOptionPane.showInputDialog(parent, message, initValue);
return input;
OptionalshowInput(String message)
show Input
return Optional.ofNullable(JOptionPane.showInputDialog(message));
OptionalshowInputInteger(String message)
show Input Integer
Optional<String> input = showInput(message);
if (input.isPresent()) {
    try {
        return Optional.of(Integer.valueOf(input.get()));
    } catch (NumberFormatException e) {
        return Optional.empty();
} else {
...
voidshowInvalidJarPathMessage(String jarPath)
show Invalid Jar Path Message
String message = "Unable to restart cmanager. Settings could not be applied.\n" + "Expected path: "
        + jarPath;
JOptionPane.showMessageDialog(null, message, "jar path", JOptionPane.ERROR_MESSAGE);
voidshowLog(int type, String title, String message)
show Log
JOptionPane.showMessageDialog(null, message, title, type);
voidshowMessage(Component c, String message, String title)
Utility method to display a popup with the provided message and title
JOptionPane.showMessageDialog(c, message, title, JOptionPane.INFORMATION_MESSAGE);