Append text in Java’s jtextarea
•
Java
There is something wrong with my text area
I use jtextarea1 Append ("smart and interesting"); Add text
First attachment:
Then I use jtextarea1 Append ("fight"); Add next text
Second attachment
What I really want is to replace "clever and interesting" with "battle" But I can't do that I tried to use jtextarea1 removeAll(); But it didn't work How to delete "clever and interesting" so that I can add "battle" to the first line
Note: "word hint" is fixed
What can I do?
Solution
If your jtextarea only contains "word hint:...", use the settext () method:
jTextArea1.setText("WORD HINT:\n" + word);
This will replace all text with what you want
BTW: removeall() is a part of the container class. Instead of deleting text, it deletes subcomponents
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码