how can I iterate over text fields not in an array

I

IKerr.

Hi,

I have some code which declares a whole bunch of text fields individually,
ie

JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField()
etc .....

how can I iterate over them ? What I want to do is something like:

String[] customerDetails = new String[19];

for(int i = 0; i<customerDetails.length;i++){
customerDetails = jTextField+i.getText();
}

This is a bit simplified because there beans on the page which inheret from
JTextField, and comboboxes which I also want to grab text from, but rather
than having to rewrite a whole load of code to make a JTextField[] or to
issue individual getText()s I was wondering if there was a way of iterating
over what I have ?

thanks

Iain
 
I

IKerr.

Please post your solution.


I couldn't find the thread at first, but:

java.awt.Component components[] = jPanel1.getComponents ();
if (components.length > 0)
{
Collection textFields = new java.util.LinkedList ();
// or ArrayList if you must

for (int i = 0; i < components.length; i++)
{
System.out.println (components.toString ());

if (components instanceof JTextField)
textFields.add (components);
}

for (java.util.Iterator it = textFields.iterator ();
it.hasNext ();)
{
JTextField tf = (JTextField)(it.next ());
System.out.println (tf.getText ());
}
}
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=m3r86ptw
9j.fsf%40gonzo.localnet&rnum=7&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%2
6oe%3DUTF-8%26selm%3Dm3r86ptw9j.fsf%2540gonzo.localnet%26rnum%3D7
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top