当我使用具有 alpha 值的前景色的 JLabel 时,如下所示:
JLabel label = new JLabel( "This is non HTML text with correct alpha color" );
label.setForeground( new Color( 1.0f, 1.0f, 1.0f, 0.5f) );
标签以 0.5-alpha 正确显示,即 50% 灰色。
但是当我将文本更改为 HTML(以更好地控制文本渲染)时,如下所示:
JLabel label = new JLabel( "<html><p>This is HTML text with incorrect alpha color</p></html>" );
label.setForeground( new Color( 1.0f, 1.0f, 1.0f, 0.5f) );
那么标签就是 100% 白色的。看来,在渲染 HTML 时,前景色的 alpha 值只是被忽略了。
我在 Windows 7 64 位下使用 Java 1.6.0_26(32 位)。
这是一个错误还是已知的限制,或者我这里有什么问题吗?
您不能将 HTML 代码和 setForeground 样式混合在一起。
See JLabel html文本忽略setFont https://stackoverflow.com/questions/7265178/jlabel-html-text-ignores-setfont?rq=1以及如何使用 JLabels(1 http://docs.oracle.com/javase/tutorial/uiswing/components/html.html)来自 Oracle 的教程。
只需使用 HTML 或 JLabel 样式即可。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)