Reputation: 53
To display a complex multi-line label with multiple styling I use Swing's html rendering capabilities and end up with really crappy font rendering.
I have tried to explicitly set the font family -
infoLabel.setText("<html><span style='font-family:Tahoma;'>My text..
But compared to non-HTML text, the JLabel with HTML text always renders very ugly, looks like ant-aliasing is not happening. I tried font smooth CSS property :
<html><span style="font-family:Tahoma;font-smooth:always;">
But the rendered html by Swing still looks ugly. If I don't use html styling in setText it looks fine. I am ensuring I am using the same font family, font size etc.
What could be the issue ?
Upvotes: 3
Views: 1464
Reputation: 19167
Try to run your program with -Dswing.aatext=true
flag, it will force it to use anti-aliasing.
If you need complex styling, you can use a JTextPane. Make it transparent, not editable, remove the border and it will look just like a label. You can apply different styles, it will be rendered with anti-aliasing and you won't have to deal with html, its support is not that good.
Upvotes: 1
Reputation: 31
I wonder if you might have to specify the style separately like
"<html><style type = 'text/css'> span {font-family: Tahoma;} ...... <span>...."
instead of adding it directly to the span tag.
Upvotes: 1