Enable text highlighting in swing message-box

try this

 JTextArea textarea= new JTextArea("add your message here");
 textarea.setEditable(true);
 JOptionPane.showMessageDialog(null, textarea, "Error", JOptionPane.ERROR_MESSAGE);

JOptionPane can be constructed with any object, not just a string message. So you could construct a JTextArea and pass that to the JOptionPane as your message. That should allow copy paste.


If you object to the white background shown by the default JTextArea, you can set the JTextArea background color equal to the JOptionPane's background color.

String title = "foo";
String message = "Select me";

JTextArea msg = new JTextArea(message);
JOptionPane pane = new JOptionPane(msg, JOptionPane.INFORMATION_MESSAGE);
msg.setBackground(pane.getBackground());
JDialog dialog = pane.createDialog(null, title);
dialog.setVisible(true);