【问题标题】:How do I append text to a text area in a Java program? [duplicate]如何将文本附加到 Java 程序中的文本区域? [复制]
【发布时间】:2013-12-22 07:07:49
【问题描述】:

我有一个名为 text_ref 的文本区域。我需要在其上附加文本,而不是过度写入。类似于日志,其中文本被附加到日志中,并且永远不会被覆盖。如何将文本附加到它?我目前正在使用“setText”。

text_ref.setText(nationality + "is the nationality...");

【问题讨论】:

  • 有 append() 方法可用。
  • -1 一看文档就会给出答案。我可以理解,如果方法的名称有些晦涩难懂,有时很难找到您要查找的内容,但伙计,append() 是列表中的第一个方法

标签: java swing user-interface awt append


【解决方案1】:

使用append方法

text_ref.append(nationality + "is the nationality...");

【讨论】:

    【解决方案2】:

    使用append方法传递字符串字面量,需要附加

      text_ref.setText(nationality + "is the nationality...");
      text_ref.append("I am just appending here to the current text");
    

    【讨论】:

      【解决方案3】:

      要在 JTextArea 子对象中附加文本,您必须使用该对象的 append 方法。

      text_ref.append("some text to append");
      

      nationality = "Polish";
      text_ref.append(nationality);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-14
        • 2016-06-08
        • 2015-11-25
        • 2013-05-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多