newbie needs your help! (JTextField)

N

Newbie

can some kind soul please help me out here?

I want to create 12 JTextFields.

I could of course write all 12 seperately like:

JTextField display1 = new JTextField();
JTextField display2 = new JTextField();
...
...
JTextField display12 = new JTextField();

Is there a way I can do this dynamically in a 'for loop'?

I have tried this, but it doesnt seem to work as I hoped for:

for (int x=0; x < 12; x++)
{
JTextField display+x = new JTextField();
}

Is there a way around what I would like to achieve?

thankyou!
 
A

ak

create array of JTextFields:
JTextField [] fields = new JTextField[12];
for(int i = 0; i < fields.length; i++) {
fields = new JTextField();
}
 
V

VisionSet

Newbie said:
can some kind soul please help me out here?

I want to create 12 JTextFields.
I could of course write all 12 seperately like:
...
Is there a way I can do this dynamically in a 'for loop'?

I have tried this, but it doesnt seem to work as I hoped for:

for (int x=0; x < 12; x++)
{
JTextField display+x = new JTextField();
}

Is there a way around what I would like to achieve?

JTextField[] f = new JTextField[12];
for(int i=0;i<f.length;i++) {
f = new JTextField();
}
 

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

Similar Threads

Needs help in logic 3
Customising Swing JTextField 3
Setting width of JTextField 2
Accessing other Frames components 2
Java Program error need help 4
Referencing the base method 6
Help with Loop 0
Help with code 0

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top