protected void displayErrorMessage(String message, Exception ex) {
JPanel messagePanel = new JPanel(new BorderLayout());
JLabel label = new JLabel(message);
messagePanel.add(label);
if (ex != null) {
JComponent panel = new JXPanel(new BorderLayout());
panel.setBorder(new RoundedBorder());
// remind(aim): provide way to allow user to see exception only if desired
StringWriter writer = new StringWriter();
ex.printStackTrace(new PrintWriter(writer));
JTextArea exceptionText = new JTextArea();
exceptionText.setText("Cause of error:\n" +
writer.getBuffer().toString());
exceptionText.setBorder(new RoundedBorder());
exceptionText.setOpaque(false);
exceptionText.setBackground(
Utilities.deriveColorHSB(UIManager.getColor("Panel.background"),
0, 0, -.2f));
JScrollPane scrollpane = new JScrollPane(exceptionText);
scrollpane.setBorder(EMPTY_BORDER);
scrollpane.setPreferredSize(new Dimension(600,240));
panel.add(scrollpane);
messagePanel.add(panel, BorderLayout.SOUTH);
}
JOptionPane.showMessageDialog(getMainFrame(), messagePanel,
resourceMap.getString("error.title"),
JOptionPane.ERROR_MESSAGE);