Update multiple JLabels dynamically

I have several JLabels and would like to be able to update these with values stored in an array.

Jlabels: companyVals0, companyVals1, companyVals2, etc
serviceVal0, serviceVal1 etc etc

   for (int x=0; x<loopLength;x++)
   {
       companyVals+x.setText(companyArr[x]);
       serviceVal+x.setText(serviceArr[x]);
       passwordVal+x.setText(passwordArr[x]);
   }

I had hoped this loop would recognize the companyVals +x = companyVals0 the first time around, then company Vals1 next....
petehindsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sciuriwareCommented:
Put those JLabels also in an array.

;JOOP!
0
petehindsAuthor Commented:
I have already tried that but if I write the below where companyVals is an array which stores CompanyVals1, CompanyVals2 etc

 for (int x=0; x<loopLength;x++)
   {
       companyVals[x].setText(companyArr[x]);
       serviceVa[x].setText(serviceArr[x]);
       passwordVal[x].setText(passwordArr[x]);
   }

It then tried to run "setText" as if it was part of the array method which of course it is not.

the syntax should be something like.

jlabelname.setText(companyArr[x]);

0
sciuriwareCommented:
You should have an array like   JLabel[] labelArray = new JLabel[sizeNeeded];
Then assign values as you create JLabels:

      JLabel k = new JLabel(); // And add it to the screen.
      labelArray[i] = k;  // Running index i

And:
      .......
      labelArray[i].setText(....................);  // That should work.

;JOOP!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petehindsAuthor Commented:
Thanks, Sorry for not getting back to you sooner.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.