Search code examples
javaswingjoptionpane

Enable text highlighting in swing message-box


Say i'm using the following code to prompt an error message in my simple swing application:

JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE);

Is there any way I could make it possible for the user to highlight text sections (for copy/paste purpose)?

Many thanks.


Solution

  • try this

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