full_prog_full
full_prog_full

Reputation: 1189

How to output fields in an ArrayList to a JTextArea?

I'm trying to do something on the lines of:

    someJtextArea.setText(String.valueOf(
    for(int i = 1; i < 0; i++)
        {
            objInstance.anArrayList.get(i).getFirstName()
        }
    ));

Upvotes: 1

Views: 130

Answers (2)

Ozzy
Ozzy

Reputation: 8322

Build your String first and then set the text.

ArrayList<String> numList = new ArrayList<String>();
numList.add("One");
numList.add("Two");
numList.add("Three");

String text = "";

for (String num : numList) {
    text += String.format("%s%n", num);
}

myTextArea.setText(text);

Upvotes: 2

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285460

Just append to the JTextArea:

Your for loop constraints by the way are a little odd.

For example:

for (Person person: objInstance.anArrayList) {
   someJTextArea.append(person.getFirstName() + "\n");
}

(Sorry about my previous wrong answer as I initially thought that you were adding to a JTextField)

Upvotes: 3

Related Questions