Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / October 2004

Tip: Looking for answers? Try searching our database.

initializing gridlayout

Thread view: 
Vince - 10 Oct 2004 17:21 GMT
I have a 6x5 grid of JTextFields.  I filled the grid quickly in the
constructor by using a FOR loop in the constructor.  The code is:

 JTextField [] text=new JTextField[30];
 for (int i=0;i<30;i++){
     text[i] =new JTextField(5);
     textEntry[i]=text[i].getText();
     panel_3.add(text[i],5); }

I want to use the text fields for user input and get the user input when a
button is pushed.  For example, in the button event I tried String
str=text[1].getText();.

The code will not compile because the text[1] variable scope is limited to
the FOR loop in the constructor.

Initializing 30 text fields does not seem like a lot.  What if there were
over a  hundred?  Would each text field have to be initialized one by one,
rather than in a loop?  Anyone have any shortcuts?

Thanks,
Vince
Paul Lutus - 10 Oct 2004 17:40 GMT
> I have a 6x5 grid of JTextFields.  I filled the grid quickly in the
> constructor by using a FOR loop in the constructor.  The code is:
[quoted text clipped - 11 lines]
> The code will not compile because the text[1] variable scope is limited to
> the FOR loop in the constructor.

Say what? No, it is not -- you declared your "text" array outside the
for-loop, so its scope is not limited as you suggest. To sort this out,
post a short, complete, compilable example program that shows the problem.

Also, what do you mean "the code will not compile"? What error message was
printed onto your computer monitor? Perhaps you could share it with us?

> Initializing 30 text fields does not seem like a lot.

State the problem you are having. You are complaining about a problem you
have not identified.

> What if there were
> over a  hundred?  Would each text field have to be initialized one by one,
> rather than in a loop?

Why are you asking this? The problem does not exist.

> Anyone have any shortcuts?

Just one. Post your code.

Signature

Paul Lutus
http://www.arachnoid.com

Vince - 10 Oct 2004 19:56 GMT
I finally got it to work.  I made variable declarations in the constructor
instead of before the constructor.

> I have a 6x5 grid of JTextFields.  I filled the grid quickly in the
> constructor by using a FOR loop in the constructor.  The code is:
[quoted text clipped - 18 lines]
> Thanks,
> Vince


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.