I am currently working on an app that adds JTextFields to a panel at runtime using:
int rowCounter = 1;
pnlRows.add(new JLabel("Row " + rowCounter));
pnlRows.add(new JTextField(20));
pnlRows.revalidate();
validate();
The problem i have is that i want to use their values in a method but have no way of referencing them.
Is there a way to do something along the lines of:
int i = 1;
JTextField row + i = new JTextField();
i++;
So that every time i run the TextField made will be called row1, row2, row3 respectively.
Thank You.
No there isn’t, what you need to do is add them to a list so that later you can get them all.
Somewhere in your class you need this:
Then when they add them you can do this:
Then finally wne you want to get them all you can iterate the list and get all the text fields out one by one.