views:

1071

answers:

3
+2  Q: 

Newline in JLabel

How can I display a newline in JLabel?

For example, if I wanted:

Hello World!
blahblahblah

This is what I have right now:

JLabel l = new JLabel("Hello World!\nblahblahblah", SwingConstants.CENTER);

This is what is displayed:

Hello World!blahblahblah

Forgive me if this is a dumb question, I'm just learning some Swing basics...

+11  A: 

Surround the string with <html></html> and break the lines with <br>.

JLabel l = new JLabel("<html>Hello World!<br>blahblahblah</html>", SwingConstants.CENTER);
freitass
thanks! that works great (just seems a little odd)
mportiz08
Thanks, I agree about the oddness.
freitass
+1  A: 
Uri
A: 

You can use the MultilineLabel component in the Jide Open Source Components.

http://www.jidesoft.com/products/oss.htm

Aakash