1

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));
}
5
  • @assylias I've tried for (int i = 0; i < GPSDataEnter.size(); i++) { LatTextData.append((String) GPSDataEnter.get(i)); } Commented Oct 21, 2012 at 19:33
  • and few others put nothing I've tried so far worked. Commented Oct 21, 2012 at 19:34
  • Does get(i) return a string or a user defined type? And by not working as expected, care to clarify? Commented Oct 21, 2012 at 19:37
  • it will be returning a string. Commented Oct 21, 2012 at 19:40
  • So.. what do you mean by not working as expected? Commented Oct 21, 2012 at 19:42

4 Answers 4

1

Try this:

string ArrayData = string.Empty;
    ArrayList listData = new ArrayList();
        foreach (string textItem in listData)

        {

        ArrayData = ArrayData + ", " + textItem;

        }

   textBox1.setText(ArrayData); 
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

Try this:

for (int i = 0; i < MyArrayList.size(); i++) {
    MyJTextField.setText(MyJTextField.getText() + MyArrayList.get(i) + "\n");
}

Your probem was rewriting!

Comments

0

I suppose your ArrayList is

ArrayList<String> arrayList;

Then,

JTextField.setText(arrayList[i]); //index of arrayList;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.