How to set line spacing/height in a JLabel in Java Swing?

fonts, html, java, jlabel, swing

Solution

This should work, but it's not. `color: green` works though.

`content.add(new JLabel("<html><p style=\"line-height: 150%;\">hi<br>world</p></html>"));`

I guess line-height doesn't work. That's how you'd do it if you were to use CSS, so maybe you can't do it that way. Here's a nice tool I found which you can use to test if your HTML will work quickly.

Problem

I have the following JLabel code: ``` JLabel someJLabel = new JLabel("<html>first line<br>second line</html>"); someJLabel.setFont(new Font("Arial", Font.PLAIN, 16)); ``` What I'd like to do is be able to control the line height/spacing between the two lines. PS: I've also looked at using paragraphs instead of breaklines, but it's the same thing. And I don't know if you can do that within an html tag without using css (you can't use css within html code in a JLabel in Java Swing).

Original source