aspose file tools
The moose likes Beginning Java and the fly likes textbox loop naming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "textbox loop naming" Watch "textbox loop naming" New topic

textbox loop naming

jason gass

Joined: Nov 11, 2004
Posts: 13
can you do a loop like this:

for (int i = 1; i<=10; i++)
textPanel.add (new JTextField(i + "") );

and name them in order, like text1,text2, text3?

So you can then refer to them like:

text1.addActionListener( textHandler );
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
If you create the references inside the loop you will not have them outside the loop.

You could create the references earlier and instantiate them (use the "new" keyword) inside a loop.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
You can access the JTextFields, without naming them

I agree. Here's the link:
subject: textbox loop naming