Escape codes not working

S

Steve

Hi all,

Why is it that the statement:

Label l = new Label("This \n Test should work");

shows the label with a block (as in, square) character instead of the linefeed?
 
M

Michael Borgwardt

Steve said:
Why is it that the statement:

Label l = new Label("This \n Test should work");

shows the label with a block (as in, square) character instead of the linefeed?

From the API doc of java.awt.Label:

"A label displays a single line of read-only text."
 
F

Fedor

Steve said:
Hi all,

Why is it that the statement:

Label l = new Label("This \n Test should work");

shows the label with a block (as in, square) character instead of the linefeed?

Have you tried carriage return (\r) or both \n and \r ?


f
 
T

Thomas Weidenfeller

Steve said:
Why is it that the statement:

Label l = new Label("This \n Test should work");

shows the label with a block (as in, square) character instead of the linefeed?

Because it is not supported. Use a TextArea instead, or use Swing and
HTML in the label.

/Thomas
 
R

Roedy Green

Label l = new Label("This \n Test should work");

shows the label with a block (as in, square) character instead of the linefeed?

Because Label is not smart enough, or rather the underlying GUI is not
smart enough. To get that effect you need Swing JLabel and use HTML
and encode your linefeed as <br>
 
J

Jacob

Roedy said:
Because Label is not smart enough, or rather the underlying GUI is not
smart enough. To get that effect you need Swing JLabel and use HTML
and encode your linefeed as <br>

Label is defined to be one line, so this has nothing
to do with lack of smartness.
Don't use HTML; Google for "MultiLineLabel" instead.
 
B

Bent C Dalager

Label is defined to be one line, so this has nothing
to do with lack of smartness.

Well, if you ask me, it would be a lot smarter for Label to support
multiline than not to.
Don't use HTML; Google for "MultiLineLabel" instead.

Why, when JLabel already does this anyway? Does MultiLineLabel do
something that JLabel can not?

Cheers
Bent D
 
R

Roedy Green

Label is defined to be one line, so this has nothing
to do with lack of smartness.

But if you ponder WHY Label was defined that way, the reason is the
that Label is a heavyweight component. It is limited by what
heavyweight Label components in various GUIs can do. In general, they
are not smart enough to handle multiline labels. Thus, Java had to
limit Label to the lowest common denominator.

In Swing, JLabel is a lightweight component. It thus does not matter
what the underlying GUI does, so JLabel can even be smart enough to
render HTML or Images.
 

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,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top