JLabel

P

pat270881

Hello,

I have a JFrame Window and a JLabel on it with a long text. The problem
is that the text of the JLabel does not fit the size of the window -
the value for the width of the window is to less. But I want not to
make the window wider. How can I make it that the text of the JLabel is
automatically divided when the end of the window width is reached and
the remaining text will be placed in the next line?

thx
 
K

Knute Johnson

pat270881 said:
Hello,

I have a JFrame Window and a JLabel on it with a long text. The problem
is that the text of the JLabel does not fit the size of the window -
the value for the width of the window is to less. But I want not to
make the window wider. How can I make it that the text of the JLabel is
automatically divided when the end of the window width is reached and
the remaining text will be placed in the next line?

thx

Probably the easiest thing to do would be to use a JTextArea instead.
See JTextArea.setLineWrap() and JTextArea.setWrapStyleWord() as well.
 
J

John McGrath

I have a JFrame Window and a JLabel on it with a long text. The problem
is that the text of the JLabel does not fit the size of the window -
the value for the width of the window is to less. But I want not to
make the window wider. How can I make it that the text of the JLabel is
automatically divided when the end of the window width is reached and
the remaining text will be placed in the next line?

That will not be easy with a JLabel. You an easily create a JLabel that
spans multiple lines (using HTML tags), but getting it to wrap is
something else.

Consider using one of the multi-line JTextComponent subclasses. You can
change the opacity, colors, font, and other properties to make it look the
same as the the JLabel.
 

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,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top