Why does Java Swing html font rendering look so crappy?
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开发者_如何学C><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 ?
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.
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.
精彩评论