如何在 ArrayList 的 textArea 中设置文本? [英] How to setText in a textArea from an ArrayList?

查看:50
本文介绍了如何在 ArrayList 的 textArea 中设置文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ArrayList ArrayListexternalDataList = new ArrayList<>(1600); 我想在 textArea 中显示前 3 个字符串,但我不能成功:

I have an ArrayList ArrayList<String> externalDataList = new ArrayList<>(1600);and I would like to display in a textArea first 3 strings, but I can't succed:

这是我的代码

textareaShowPreview.setPrefRowCount(3);

Iterator<String> it = externalDataList.iterator();
       int tot = 0;
       while(it.hasNext() && tot<3){
           String element = it.next();
           textareaShowPreview.setText(element + "\n");
           System.out.println("elements are: " + element);
           tot++;
       }

sout 正确打印前 3 个字符串

The sout correctly print first 3 strings

element are: 23/05/2007 ,30.9455,31.2545,30.9091,30.9545,7518142
element are: 24/05/2007 ,30.6545,31.0909,30.5364,30.6909,12851606
element are: 25/05/2007 ,30.6636,30.8545,30.4818,30.8091,9392088

但在 textArea 我只有第一个

but in textArea I have only first one

如何修改我的代码以在 textArea 中显示所有三个字符串,每行一个字符串?

How do I have to modify my code to show in textArea all three strings, one string per row?

推荐答案

使用 appendText 而不是 setText 这里是一个链接.

Use appendText instead of setText here is a link.

setText,删除之前的文本并设置你给它的文本.append 将当前文本保留在您的文本区域中.

The setText, delete the previous text and set the text you are giving to it. The append keep the current text in your text area.

希望能帮到你!

这篇关于如何在 ArrayList 的 textArea 中设置文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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