Damir
Damir

Reputation: 56189

Two rows of text inside a JLabel

How to write text in two rows inside a JLabel ( It doesn't work with \n ) ?

Upvotes: 2

Views: 6408

Answers (5)

Eagle
Eagle

Reputation: 349

Here is also solution if you want to center the two lines in the jlabel.

JLabel label = new JLabel("<html> <center> line1 </center> <center> line2 </center> </html>");

Upvotes: 0

Costis Aivalis
Costis Aivalis

Reputation: 13728

Try to make it like this:
JLabel myLabel = new JLabel("<html>this is line1<br>this is line2</html>");

Upvotes: 7

user467871
user467871

Reputation:

jLabel.add("<html>a<br/>b</html>");

Upvotes: 2

Jigar Joshi
Jigar Joshi

Reputation: 240860

go for "<html> one <br/> two </html>"

Upvotes: 2

dogbane
dogbane

Reputation: 274532

JLabel label = new JLabel("<html>Two<br/>lines</html>");

See How to Use HTML in Swing Components

Upvotes: 6

Related Questions