Runeony1
Runeony1

Reputation: 229

How to add new line in a JLabel with variables

I understand you can make a new line using <html> <br> </html> but when I add a variable (is a string type) to the text of a label this command doesn't work any more.

label.setText("blahblahblah" + variable + "<html><br>blahblahblah</html>");

I need it to output:

blahblahblah
blahblahblah

Upvotes: 7

Views: 6228

Answers (2)

AsirC
AsirC

Reputation: 459

It should be:

label.setText("<html>blahblahblah" + variable + "<br>blahblahblah</html>");

Upvotes: 5

mercutio
mercutio

Reputation: 1066

You need to have the <html> tag as the first thing in your String:

label.setText("<html>blahblahblah" + variable + "<br>blahblahblah</html>");

Upvotes: 8

Related Questions