Search code examples
javajtextareamalformedurlexception

Displaying MalformedURLException in JTextArea


I am working on Java program having several components. What I am trying to achieve is, that any Exception be displayed in the JTextArea, and not in the console. The code below doesn't work. What can I do?

catch ( MalformedURLException e) { textArea.append(e); }

Thank you


Solution

  • The JTextArea does not support the append() method. You could try this if you just need to display the error:

    catch ( MalformedURLException e) { textArea.setText(e.toString()); }
    

    You could try this if you need to append the message:

    catch ( MalformedURLException e) { textArea.setText(textArea.getText()+e.toString()); }