Reputation: 2009
I'm not too familiar with Java GUI programming, and I wanted to do something where I have a loop that spits out a list of stuff and have the JTextField render it in the order it comes out.
I just do not know how the second parameter of the JTextField insert() function works. Right now when I do something like:
for(int i = 0; i < list.size(); i++){
textArea.insert(list.get(i), 0);
}
It does what I want, except it lists everything in backwards order that I put it in. I want it to display everything the other way around.
Thank you for any advice.
Upvotes: 1
Views: 2282
Reputation: 1287
All you need to define a temporary string, result
and for every item in the list add the string representation to that variable. When you have looped through everything, all you need to do is textArea.setText(result)
.
String result = "";
for(int i = 0; i < list.size(); i++)
{
result += list.get(i).toString();
}
textArea.setText(result);
Upvotes: 1