I am dynamically creating jtextfields and I was wondering if there was a way to loop through each one and check for it’s value
something like this:
foreach(JTextField:jtf in JFrame)
System.out.prinlnt(jtf.getText());
Edit:
The current way I’m doing this is creating an array list:
private ArrayList<JTextField> txtFields = new ArrayList<JTextField>();
When I call createDynamic:
final JTextField txtDirPath = new JTextField(20);
txtFields.add(txtDirPath);
Then on my button I have an action which perform this:
for (int i = 0; i < txtFields.size(); i++) {
String strPath = txtFields.get(i).getText();
System.out.println(txtFields.size());
System.out.println(strPath);
}
Just put you text fields in a list (
java.util.List<JTextField>) when creating them dynamically, and loop over this list :