• Post Reply Bookmark Topic Watch Topic
  • New Topic

JLabel  RSS feed

 
P Veer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to create an array of JLabels and then initialise "n" JLabels to different values in a loop.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Paveen -
Welcome to JavaRanch.
I'm pretty sure you won't see a question like this on the SCJP certification exam, especially the 1.4 exam. Are you asking for a particular project? Maybe this question belongs in another forum.
Also, could you provide the context? Sometimes the answer may be different depending on the context.
Thanks.
 
P Veer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam new here so maybe I put it in the wrong Place.
Maybe,this doesnt belong here.But appreciate ur help......

Here's the context:
Iam trying to read n inputs using jlabels and jtext fields.
n is user defined.
Then I want to generate n JLabels and n Jtext fields using a loop.
I want to add All of them onto one content pane.

:All this effort is to read an input into a n x 3 matrix.
Thanks in advance.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never used an array of JLabels, but I have had to change the text of existing JLabels. For this, use the method setText(String t). (Have you tried this? How are you trying to set the text?)
The way to use the JLabel methods is:

Then add this to your content frame. I see no reason why this couldn't be extended to an array of JLabels updated from an array of Strings. One warning though: if you try to initialize the JLabel from the user's input, the compiler will complain.
Hope this helps. If not, please post the code for the loop you're using, and I'll see if I can find the problem. Please be sure to use the UBB tags for code.
[ October 21, 2003: Message edited by: Jeff Bosch ]
 
P Veer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.I think that solves the problem.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. You're welcome.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!