File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "textbox loop naming" Watch "textbox loop naming" New topic
Author

textbox loop naming

jason gass
Greenhorn

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: http://aspose.com/file-tools
 
subject: textbox loop naming