Can JLabel have 2 rows of text?

R

Rpng123

Hello,

I have a JLabel in a JPanel which is in BorderLayout. I would like to have 2
rows of text (static text) in the JLabel. Actually, I want 2 rows of text
(just informational) on the top left corner of the JPanel.

Msg1 Instructions...
Msg2 Instructions...

Is this possible? I am having a difficult time with formatting in Java. I
thought about just using 2 JLabels, but I would have to put the JPanel in
GridLayout. Can I use \n in the JLabel text? If multiple rows of text is
possible in JLabel - how to do this? If not, how can I place two rows of text
on the top left corner of JPanel? Note: I will also be drawing stuff on the
JPanel.

Thanks,
Rich
 
C

Chris Smith

Rpng123 said:
I have a JLabel in a JPanel which is in BorderLayout. I would like to have 2
rows of text (static text) in the JLabel. Actually, I want 2 rows of text
(just informational) on the top left corner of the JPanel.

Msg1 Instructions...
Msg2 Instructions...

Is this possible? I am having a difficult time with formatting in Java. I
thought about just using 2 JLabels, but I would have to put the JPanel in
GridLayout. Can I use \n in the JLabel text?

I don't know off-hand, but why not try it? If not, one thing that
definitely will work is to use html for the label. Set the label's text
to "<html>line1<br>line2</html>".

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Rpng123

My NG browser interpreted your html code. I am guessing it is <br> ("<" "b"
">"). Well, I tried that in my JLabel text, but everything was still on one
line.

jLbl.setText("line1 <br> line2")

This did not give me

line1
line2

just line1"<" b ">" line2

But thanks for the suggestion.
 
K

KS

My NG browser interpreted your html code. I am guessing it is <br> ("<" "b"
">"). Well, I tried that in my JLabel text, but everything was still on one
line.

jLbl.setText("line1 <br> line2")

This did not give me

line1
line2

just line1"<" b ">" line2

But thanks for the suggestion.

Maybe you should read again the advice Chris gave you and do as he says.
It works.

-Kari
 
S

Steve W. Jackson

:My NG browser interpreted your html code. I am guessing it is <br> ("<" "b"
:">"). Well, I tried that in my JLabel text, but everything was still on one
:line.
:
:jLbl.setText("line1 <br> line2")
:
:This did not give me
:
:line1
:line2
:
:just line1"<" b ">" line2
:
:But thanks for the suggestion.
:

That's because you didn't do what the other poster suggested, which was
to use properly constructed HTML in your label's value. He did't say to
put a "<br>" there, he said to use "<html>line1<br>line2</html>". Trust
him -- it works. It MUST begin with the opening html tag.

= Steve =
 
C

Chris Smith

Rpng123 said:
My NG browser interpreted your html code. I am guessing it is <br> ("<" "b"
">"). Well, I tried that in my JLabel text, but everything was still on one
line.

jLbl.setText("line1 <br> line2")

This did not give me

line1
line2

just line1"<" b ">" line2

But thanks for the suggestion.

Okay. That would be a reason to look for a new newsreader. MicroPlanet
Gravity is excellent. Anyway, see if this is visible in your
newsreader:

It needs to be "&lt;html&gt; line1 &lt;br&gt; line2 &lt;/html&gt;"

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Rpng123

OK. I got it! Thank you very much for escaping those characters &lt; Yes.
This worked great. Java is real cool! I am relatively new to it.

As for the browser problem, my company has this big fat firewall and can't
access NGs from there. So they gave me an old NT4 standalone workstation with
a modem that I loaded Aol5 (only version NT4 supported). Yeah, I know, I
should even have an Aol account, but even though I wear the pants at my place,
the high heels call the shots :).

Thank you all for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top