0

I made an ArrayList of arrays of JTextField. Now I want to get the value of the first position of the array that was previously stored in the ArrayList.

ArrayList <JTextField []> text_field;
text_field = new ArrayList <JTextField []> ();

I have tried doing this:

text_field.get (row)[column];

But this didn't work. How should I change it?

And how can I add the JTextField onto the panel?

for (int i = 0; i < text_field.size (); i++) {
  for (int j = 0; j < 8; j++) {

  }
}
Eileen Li
  • 43
  • 6
  • What are the types of `row` and `column`? – SamTebbs33 Jun 13 '16 at 00:40
  • row and column are just index numbers – Eileen Li Jun 13 '16 at 00:45
  • What do you mean by "doesn't work"? Do you get a runtime exception or compiler error? If so, please post it. (Remember to tag me in your reply). – SamTebbs33 Jun 13 '16 at 00:48
  • I am really confused why people will use the conveience of Lists and then also use Array - why not `ArrayList>` – Scary Wombat Jun 13 '16 at 00:49
  • The second part of your question - how to add components to the JPannel, was discussed [here](http://stackoverflow.com/questions/13907202/adding-components-into-jpanel-inside-a-jframe). [This](https://docs.oracle.com/javase/tutorial/uiswing/components/panel.html#add) is from official Java Tutorials. – Janez Kuhar Jun 13 '16 at 13:43

1 Answers1

0

Try this:

((JTextField[]) text_field.get(row))[column];
Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45
  • Well on my JVM both statements compile and run without errors. I've actually answered this question before checking your statement. So this is a mystery to me. What Java version / platform are you on? And what type of error were you getting? – Janez Kuhar Jun 13 '16 at 13:37