Java JOptionPane Error displayErrorMessage(final Throwable throwable, final Component parentComponent)

Here you can find the source of displayErrorMessage(final Throwable throwable, final Component parentComponent)

Description

display Error Message

License

Apache License

Declaration

public static void displayErrorMessage(final Throwable throwable, final Component parentComponent) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.swing.*;

import java.awt.*;

import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    public static void displayErrorMessage(final Throwable throwable, final Component parentComponent) {
        StringWriter stackTrace = new StringWriter();
        throwable.printStackTrace(new PrintWriter(stackTrace));
        JTextArea textArea = new JTextArea(stackTrace.toString(), 25, 100);
        textArea.setEditable(false);/*from   www .j  a va 2 s  .  co  m*/
        textArea.setTabSize(4);
        textArea.setForeground(Color.RED);
        textArea.setFont(textArea.getFont().deriveFont(12f));
        JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(parentComponent), new JScrollPane(textArea),
                "Unhandled Error", JOptionPane.PLAIN_MESSAGE, null);
    }
}

Related

  1. displayError(String message)
  2. displayError(Throwable e)
  3. displayErrorMessage(Component component, Throwable t)
  4. displayErrorMessage(Component parent, String message)
  5. displayErrorMessage(Component parentComponent, String message, String windowTitle)
  6. displayErrorMessage(String msg, Throwable t)
  7. displayErrors(Component parent, List errors)
  8. errMsg(Component owner, String msg, Exception e)
  9. errMsg(final Component owner, final String msg, final Throwable e)