JPanel panel = new JPanel(new BorderLayout());
JLabel label = new JLabel("Unexpected error occurred: '" + th.getMessage() + "' with stack trace:", UIManager.getIcon("OptionPane.errorIcon"), SwingConstants.LEFT);
label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panel.add(label, BorderLayout.NORTH);
final JTextArea text = new JTextArea(new String(bos.toByteArray()));
text.setEditable(false);
text.setRows(10);
text.setColumns(50);
panel.add(new JScrollPane(text), BorderLayout.CENTER);
final JDialog dialog = new JDialog(getOwner(), "SQLJet Error", true);
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton button = new JButton("Close");
button.setMnemonic('C');
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
dialog.dispose();
}
});
JButton copyButton = new JButton("Copy");
copyButton.setMnemonic('o');
copyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
StringSelection trace = new StringSelection(text.getText());
Clipboard cp = Toolkit.getDefaultToolkit().getSystemClipboard();
cp.setContents(trace, trace);
}
});
buttonPanel.add(copyButton);