我想将数组列表中的所有值显示在文本区域中,我该如何实现?

huangapple go评论74阅读模式
英文:

I want to Display all values in arraylist to textarea, How can I achieve that?

问题

public void printAllValues(){
    try {
        ExpenseDAO exdao = new ExpenseDAO();
        ArrayList<String> list = exdao.getAllexpenses();
        for (int i = 0; i < list.size(); i++)
            txtexpense.setText(list.get(i));
    } catch (Exception ex) {
        Logger.getLogger(ExpenseManager.class.getName()).log(Level.SEVERE, null, ex);
    }
}
英文:

I want to Display all the items in a array list into text area. I tried following but it only display last item.

public void printAllValues(){
    try {
        ExpenseDAO exdao = new ExpenseDAO();
        ArrayList&lt;String&gt; list = exdao.getAllexpenses();
        for (int i = 0; i &lt; list.size(); i++)
        txtexpense.setText(list.get(i));
    } catch (Exception ex) {
        Logger.getLogger(ExpenseManager.class.getName()).log(Level.SEVERE, null, ex);
    }
    

}

答案1

得分: 3

txtexpense.append(list.get(i));

无论是swing还是javafx我确定两者都有TextArea.append(String str)方法
当你设置文本时它会用提供的字符串完全替换所有文本

如果没有TextArea.append()那么你可以创建一个字符串将所有列表值都连接在一起
英文:
txtexpense.append(list.get(i));

Whether it's swing or javafx, I'm sure both have TextArea.append(String str) methods.
When you set the text, it replaces all of it with the string provided.

if there is no TextArea.append() then you can create a string and concatenate all of the list values together.

huangapple
  • 本文由 发表于 2020年10月18日 00:26:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/64404692.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定