This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "JLabel" Watch "JLabel" New topic
Author

JLabel

P Veer
Greenhorn

Joined: Oct 21, 2003
Posts: 9
How to create an array of JLabels and then initialise "n" JLabels to different values in a loop.


maverickthinker
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
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.


Give a man a fish, he'll eat for one day. <br />Teach a man to fish, he'll drink all your beer.<br /> <br />Cheers,<br /> <br />Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
P Veer
Greenhorn

Joined: Oct 21, 2003
Posts: 9
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

Joined: Jul 30, 2003
Posts: 804
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

Joined: Oct 21, 2003
Posts: 9
Thanks.I think that solves the problem.
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
Cool. You're welcome.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JLabel
 
Similar Threads
JLabel
JButtons not buttons?
Image Overlapping not proper
how to perform mouse listener for an open street map
Layout Issues