为什么Java Swing html字体渲染看起来很糟糕? [英] Why does Java Swing html font rendering look so crappy?
问题描述
我试图明确地设置字体族 -
infoLabel.setText(< html>< span style ='font-family:Tahoma;' > My text ..
但与非HTML文本相比,带HTML文本的JLabel始终呈现非常丑,看起来像蚂蚁别名没有发生。我试过字体流畅的CSS属性:
< html>< span style =font-family:Tahoma; font-smooth:always;>
如果我不在setText中使用html样式,它看起来很好。我确保我使用相同的字体系列,字体大小等。
可能是什么问题?
尝试用运行程序-Dswing.aatext = true
标志,它会fo如果你需要复杂的样式,你可以使用JTextPane。使其透明,不可编辑,删除边框,它会看起来就像一个标签。你可以应用不同的风格,它将被渲染与反锯齿,你将不必处理HTML,它的支持是不是很好。
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 ?
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.
这篇关于为什么Java Swing html字体渲染看起来很糟糕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!