Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to Implement array of Components?  RSS feed

 
Shay Gaghe
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Coders
i developing a Swing interface and i have lots of components that i would like to hold within an array:
i was thinking about :
JLabel labs = (label1,label2,label3,label5...);
in the constructor:

whenever i doing it i recieve a compiler error:
"ClientProfile.java": Error #: 300 : variable label1 not found in class ClientProfile at line 16, column 20
what im doing wrong?
how can i implements it correctly (code example please)?
can i use "for" loop outside of any function?
thanks in advance
Shay
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post what you have on line 16 in your code?

In the code snippet you provided there is no variable named label1, so the error isn't in that part of your code...

Just a shot in the dark, but did you remember to instantiate the array?



If you're going to use the :

form of creating an array, all the elements that are going into the array have to exist...


or:



-Nate
 
Shay Gaghe
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply
you explain it very well. i was thinking that i can create array of components like i use to create array of String.now i know that i have to create them before put them into an array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!