4

I have a problem with my text area.

I use jTextArea1.append("cleverly amusing"); to add the text..

FIRST APPEND:

then I use jTextArea1.append("a fight"); to add the next text.

SECOND APPEND

enter image description here

What I Really want is to replace the "cleverly amusing" to "a fight". But I cannot do it. I tried to use the jTextArea1.removeAll(); but there's no effect. How can I remove the "cleverly amusing" so that I can append the "a fight" to the first line.

NOTE: "WORD HINT" is fixed...

What can I do?

4

3 回答 3

10

如果您的 JTextArea 将包含“WORD HINT: ...”,则使用setText () 方法:

jTextArea1.setText("WORD HINT:\n" + word);

这将用您想要的内容替换所有文本。

BTW : removeAll () 是 Container 类的一部分,不是删除文本而是删除子组件。

于 2011-01-31T15:55:25.753 回答
2

为什么不使用setText(String text)代替append(String text)

于 2011-01-31T15:54:19.567 回答
1

而不是removeAll,只需setText()使用您想要的第一行调用,然后您可以根据需要附加其他数据。

于 2011-01-31T15:55:29.983 回答