pasindu229
pasindu229

Reputation: 27

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

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

}

Upvotes: 0

Views: 132

Answers (1)

user14410324
user14410324

Reputation:

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.

Upvotes: 3

Related Questions