Add your message to a text component that can wrap, such as JEditorPane, then specify the editor pane as the message to your JOptionPane. See How to Use Editor Panes and Text Panes and How to Make Dialogs for examples.
Addendum: As an alternative to wrapping, consider a line-oriented-approach in a scroll pane, as shown below.

f.add(new JButton(new AbstractAction("Oh noes!") {
    @Override
    public void actionPerformed(ActionEvent action) {
        try {
            throw new UnsupportedOperationException("Not supported yet.");
        } catch (Exception e) {
            StringBuilder sb = new StringBuilder("Error: ");
            sb.append(e.getMessage());
            sb.append("\n");
            for (StackTraceElement ste : e.getStackTrace()) {
                sb.append(ste.toString());
                sb.append("\n");
            }
            JTextArea jta = new JTextArea(sb.toString());
            JScrollPane jsp = new JScrollPane(jta){
                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(480, 320);
                }
            };
            JOptionPane.showMessageDialog(
                null, jsp, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}));
 
        
        
` instead. – Math Feb 17 '14 at 13:41