在JtextArea的末尾添加一个新行 [英] Add a new line to the end of a JtextArea

查看:117
本文介绍了在JtextArea的末尾添加一个新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本区域,里面有一些文字,我想再添加一些线条(第一行+我要添加的其他行),但它不起作用。

I have a text area with some text in it and I want to add some lines to it again, (the first lines + the other lines that I want to add) but it doesn't work.

我现在正在这样做的方式删除旧文本并仅显示新行。

The way I'm doing it right now erases the old text and shows just the new lines.

推荐答案

使用 JTextArea.setText(String text),而不是 JTextArea.append(字符串文本)

Instead of using JTextArea.setText(String text), use JTextArea.append(String text).


将给定文本追加到最后该文件。如果模型为null或字符串为null或为空,则不执行任何操作。

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 的末尾添加文字。

This will add text on to the end of your JTextArea.

另一个选择是使用 getText() JTextArea获取文本,然后操纵String(添加或删除或更改String),然后使用 setText(String text)设置<$ c $的文本c> JTextArea 成为新的String。

Another option would be to use getText() to get the text from the JTextArea, then manipulate the String (add or remove or change the String), then use setText(String text) to set the text of the JTextArea to be the new String.

这篇关于在JtextArea的末尾添加一个新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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