Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add text to a JTextArea [duplicate]

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.

like image 939
Bill Nye Avatar asked Oct 19 '25 13:10

Bill Nye


2 Answers

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

like image 74
Mohammed Aouf Zouag Avatar answered Oct 21 '25 04:10

Mohammed Aouf Zouag


You should use the append and insert methods.

like image 34
Sanjay Manohar Avatar answered Oct 21 '25 03:10

Sanjay Manohar