Java JLabel在呈现HTML时忽略前景色的Alpha值 [英] Java JLabel ignores alpha value of foreground color when rendering HTML

查看:102
本文介绍了Java JLabel在呈现HTML时忽略前景色的Alpha值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用具有alpha值的前景颜色的JLabel时,如下所示:

  JLabel label = new JLabel (这是不正确的alpha颜色的HTML文本); 
label.setForeground(new Color(1.0f,1.0f,1.0f,0.5f));

标签可正确显示0.5-alpha,因此50%为灰色。



但是,当我将文本更改为HTML(以更好地控制文本呈现)时,如下所示:

  JLabel label = new JLabel(< html>< p>这是带有不正确字母颜色的HTML文本< / 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样式混合在一起。

请参阅 JLabel html文本忽略setFont 和如何使用JLabels( 1 < a>)教程。



只需使用HTML或JLabel样式。


When I use a JLabel with a foreground color which has an alpha value, like so:

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) );

the label is displayed correctly with 0.5-alpha, so 50% gray.

But when I change the text to HTML (to have more control over the text rendering), like so:

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) );

Then the label is 100% white. It seems, while rendering HTML, the alpha value of the foreground color is just being ignored.

I'm using Java 1.6.0_26 (32bit) under Windows 7 64 Bit.

Is this a bug or a known limitation, or do I anything wrong here?

解决方案

You cannot mix HTML code and setForeground styling together.

See JLabel html text ignores setFont and How to use JLabels(1) tutorial from oracle.

Just use either HTML or JLabel styling.

这篇关于Java JLabel在呈现HTML时忽略前景色的Alpha值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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