dynamic creation of JTextField & getting the value from each field
Dear All,
I have a loop which creates JTextField and adds them to a JPanel.
for (Iterator experimentIt = statisticsType.iterator(); experimentIt.hasNext(); ){
String item = (String) experimentIt.next();
statsfilterspanel.add(new JTextField());
}
I cant seem to figure out a way to getText() from each of these JTextFields as their instance dont have a name.
Is there a way to dynamically create JTextFields and keep a track of which JTextField has what value?
Many thanks in advance.
Anuj.
[671 byte] By [
agoela] at [2007-10-3 10:26:09]

> I am not sure how many textfields I need and I am not> interested in hardcoding a fixed number of textfields> in an array.> > Is there another way?Yes, don't hardcode, do it dynamically.
Hello,It will be nice if you can paste a sample code or redirect me to a relevant post in the forum to create new JTextFields dynamically. I tried looking for it and was not able to find something useful for me.Thanks much appreciated.RegardsAnuj
> Hello,
>
> It will be nice if you can paste a sample code or
> redirect me to a relevant post in the forum to create
> new JTextFields dynamically.
>
> I tried looking for it and was not able to find
> something useful for me.
How where you planning to do it with a hardcoded value? Just replace the value with whatever the dynamic value would be.
// Make this a class variable to it can be accessed in any method
ArrayList textFields = new ArrayList();
...
for (Iterator experimentIt = statisticsType.iterator(); experimentIt.hasNext(); ) {
String item = (String) experimentIt.next();
//statsfilterspanel.add(new JTextField());
JTextField textField = new JTextField();
statsfilterpane.add( textField );
textFields.add( textField );
}