 <p>Add your message to a text component that can wrap, such as <code>JEditorPane</code>, then specify the editor pane as the <code>message</code> to your <code>JOptionPane</code>. See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html" rel="nofollow noreferrer"><em>How to Use Editor Panes and Text Panes</em></a> and <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html" rel="nofollow noreferrer"><em>How to Make Dialogs</em></a> for examples.</p> <p>Addendum: As an alternative to wrapping, consider a line-oriented-approach in a scroll pane, as shown below.</p> <p><img src="https://i.stack.imgur.com/hBAEe.png" alt="error image"></p> <pre><code>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); } } })); </code></pre>