Java JOptionPane Error showErrorDialog(JFrame parent, Exception ex)

Here you can find the source of showErrorDialog(JFrame parent, Exception ex)

Description

show Error Dialog

License

Open Source License

Declaration

public static void showErrorDialog(JFrame parent, Exception ex) 

Method Source Code

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

import java.awt.Dimension;
import java.awt.Font;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Main {
    public static void showErrorDialog(JFrame parent, Exception ex) {
        JTextArea textArea = new JTextArea();
        textArea.setFont(new Font("Sans-Serif", Font.PLAIN, 10));
        textArea.setEditable(false);//  w  ww.j av  a 2  s. c om
        StringWriter writer = new StringWriter();
        ex.printStackTrace(new PrintWriter(writer));
        textArea.setText(writer.toString());

        JScrollPane scrollPane = new JScrollPane(textArea);
        scrollPane.setPreferredSize(new Dimension(350, 150));

        JOptionPane.showMessageDialog(parent, scrollPane, "An Error Has Occurred", JOptionPane.ERROR_MESSAGE);
    }
}

Related

  1. showError(Throwable e)
  2. showError(Window parent)
  3. showErrorBox(Component aParent, String aTitle, String aMessage)
  4. showErrorBox(Component pParent, String pMessage, String pTitle)
  5. showErrorConfirmBox(Component pParent, String pMessage, String pTitle, String pLeftOption, String pRightOption)
  6. showErrorMessage(Component c, Exception e)
  7. showErrorMessage(Component parent, String message)
  8. showErrorMessage(Component parent, String str)
  9. showErrorMessage(Component parent, String str)