Reputation: 19
i have 30 jtextfield: jTextField1..through..jTextField30 ; to avoid redundancy i'm trying to clear all fields in for loop such that:
for (int i=1;i<31;i++)
{
jTextField(String.valueOf(i)).setText("")
}
but it is error in this way , how to do it ?
Upvotes: 0
Views: 68
Reputation: 838
So you need something like this
ArrayList<JTextField> fields = new ArrayList<JTextField>(); //This needs to be populated with your JTextFields
for(int i = 0; i < fields.size(); i++)
if(fields.get(i) != null)
fields.get(i).setText("");
Upvotes: 1