Reputation: 470
I'm trying to display data that I have stored in an ArrayList into JtextField. for example I would like to get the (ID,Name,Age,Gender) at point 0 in the array and display them into JtextFields.
I have tried the code below but it does not work as expected:
for (int i = 0; i < GPSDataEnter.size(); i++) {
LatTextData.append((String) GPSDataEnter.get(i));
}
Upvotes: 1
Views: 7296
Reputation: 11
Try this:
for (int i = 0; i < MyArrayList.size(); i++) {
MyJTextField.setText(MyJTextField.getText() + MyArrayList.get(i) + "\n");
}
Your probem was rewriting!
Upvotes: 1
Reputation: 17665
Try this:
string ArrayData = string.Empty;
ArrayList listData = new ArrayList();
foreach (string textItem in listData)
{
ArrayData = ArrayData + ", " + textItem;
}
textBox1.setText(ArrayData);
Upvotes: 1
Reputation: 2751
I suppose your ArrayList is
ArrayList<String> arrayList;
Then,
JTextField.setText(arrayList[i]); //index of arrayList;
Upvotes: 0
Reputation: 58705
You can use the .setText() method of the JTextField. Here is the documentation http://docs.oracle.com/javase/6/docs/api/javax/swing/JTextField.html
A short example:
ArrayList<String> myList = new ArrayList<String>();
... Fill up the list somehow ...
JTextField myField = new JTextField();
myField.setText(myList.get(0));
Upvotes: 1