英文:
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<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);
}
}
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论