在Java的JTextArea中附加文本 [英] Appending text in Java's JTextArea

查看:207
本文介绍了在Java的JTextArea中附加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文字区域有问题。

我使用 jTextArea1.append(聪明有趣); 添加文字..

第一个附录:

然后我用 jTextArea1.append(打架) ; 添加下一个文本。

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

第二个附件

我真正想要的是将巧妙有趣替换为一场战斗。但我不能这样做。我试图使用 jTextArea1.removeAll(); ,但没有效果。如何删除巧妙有趣,以便我可以将一场战斗附加到第一行。

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.

注意:WORD HINT是固定的......

NOTE: "WORD HINT" is fixed...

我该怎么办?

推荐答案

如果你的JTextArea会包含WORD HINT:...然后使用 setText ()方法:

If your JTextArea will only contain "WORD HINT: ..." then use the setText() method:

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

这将取代你想要的所有文字。

This will replace all the text with what you want.

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

BTW : removeAll() is part of the Container class, and is not to remove text but child components.

这篇关于在Java的JTextArea中附加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆