简体   繁体   中英

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

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM