我有一个文本区域,其中包含一些文本,我想再次向其中添加一些行(第一行 + 我要添加的其他行)但它不起作用。
我现在的做法是删除旧文本并只显示新行。
最佳答案
不要使用 JTextArea.setText(String text)
,而是使用 JTextArea.append(String text)
.
Appends the given text to the end of the document. Does nothing if the model is null or the string is null or empty.
这会将文本添加到 JTextArea
的末尾。
另一种选择是使用 getText()
从 JTextArea
获取文本,然后操作字符串(添加或删除或更改字符串),然后使用setText(String text)
将 JTextArea
的文本设置为新的 String。
关于java - 在 JtextArea 的末尾添加一个新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2088016/