Search code examples
javaswingjtextarea

How do you add text to a JTextArea


I am making a simple NotePad app in my spare time and i have added some buttons to add some text, like the time or an essay plan etc. I am currently using the code

textArea.setText("Text");

But it keeps on replacing all of the text, is there anyway to just add the text to the JTextArea? I've tried

textArea.addText("Text"); 

and it doesn't seem to work.


Solution

  • You need to use textArea.append("text");