How to setText in a textArea from an ArrayList?

左心房为你撑大大i 提交于 2019-12-11 03:37:30

问题


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:

Here is my code

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++;
       }

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

but in textArea I have only first one

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


回答1:


Use appendText instead of setText here is a link.

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.

Hope it helps!



来源:https://stackoverflow.com/questions/17103275/how-to-settext-in-a-textarea-from-an-arraylist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!