为什么Java Swing html字体渲染看起来很糟糕? [英] Why does Java Swing html font rendering look so crappy?

查看:1055
本文介绍了为什么Java Swing html字体渲染看起来很糟糕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了显示一个复杂的多行标签,我使用了Swing的html渲染功能,并且渲染出了非常糟糕的字体。



我试图明确地设置字体族 -

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆