[JLabel] HTML + Font
843806Nov 12 2008 — edited Nov 15 2008Hi,
I have a JLabel in which I use HTML to color my text (the color is not the same for all the text)?
ex :
JLabel label = new JLabel("<html><body>font color='blue'>hi</font> to <font color='red'>you</font></body></html>);
Then, I set a customized font that I load dynamically:
InputStream inputFont = this.getClass().getResourceAsStream("my_font.ttf");
Font font = Font.createFont(Font.TRUETYPE_FONT, inputFont);
MY_FONT = font.deriveFont(24f);
label.setFont(MY_FONT);
*My problem is:*
When I do that, the font is not applied (problably because of HTML font tags). I just see for a moment my font with the HTML tags, and when the HTML is parsed, the default font comes back. I've tried to change <font> by <span>, it does just the same)
When I remove HTML tags from my JLabel, like new JLabel("plop") and apply my customized font, I have no problem and my font is applied (but I don't have the colors that I want).
Problem is I want both of it! My customized font AND colors.
Do you know how to do that?
I hope I made myself clear,
Thanks :)