Ask coding questions

← Back to all posts
Newline with JLabel
GeneralBaker

How do I add a newline to my text in a JLabel?

Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
GeneralBaker
Comments
hotnewtop
SixBeeps

What happens if you put \n in the text value?

GeneralBaker

In the case of
JLabel l = new JLabel("Stuff\n Is Cool");

the label's text becomes:
Stuff Is Cool

Not:
Stuff
Is Cool

Hope that makes sense...
@SixBeeps

SixBeeps

@GeneralBaker Hmm, maybe try this?
new JLabel("<html>Stuff<br>Is Cool</html>");

From here: https://stackoverflow.com/questions/685521/multiline-text-in-jlabel

GeneralBaker

Thanks! It worked [email protected]

Coder100

Does \n not work?