将 nimbus 私有类 `DerivedColor` 解码为正确的 ARGB 值
我正在开发适合 Nimbus 外观和感觉的自定义组件。我遇到了颜色默认值的问题,就像 Java 1.6 中的“nimbusBlueGrey”返回 com.sun.java.swing.plaf.nimbus.DerivedColor 的实例一样>。
由于这是一个私有类,而且它在 Java 7 中无论如何都会发生变化,因此我需要将其视为 java.awt.Color
的实例。但是当我尝试混合颜色,例如调整色调、饱和度和亮度时,这些邪恶的对象返回错误的 RGB 颜色。 toString 输出表明了这个问题:
DerivedColor(color=50,50,50 parent=nimbusBase offsets=0.03245944,-0.525188,0.196078,0)
所以我希望能够将其读取为 ARGB 0xffa9b0be ,这是正确的(参见 Nimbus 默认值)——但是我从 getRGB
得到的是没用的0x00323232
吗?
I am developing custom components which fit into the Nimbus look and feel. I'm running into a problem with the color defaults which, as with "nimbusBlueGrey"
in Java 1.6 return instances of com.sun.java.swing.plaf.nimbus.DerivedColor
.
Since this is a private class and it would anyway change in Java 7, I need to treat this like an instance of java.awt.Color
. But when I try to mix the color, e.g. adjust hue, saturation, and brightness, these evil objects return wrong RGB colors. The toString
output indicates this problem:
DerivedColor(color=50,50,50 parent=nimbusBase offsets=0.03245944,-0.525188,0.196078,0)
So I want to be able to read this as ARGB 0xffa9b0be
which would be correct (cf. Nimbus Defaults) -- but what I get from getRGB
is that useless 0x00323232
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 Nimbus 不是当前的外观时,就会出现问题。似乎
DerivedColor
查找当前的外观,然后无法解码父颜色。因此,解决方案是在未设置 Nimbus 的情况下使用默认颜色的副本。
The problem occurs when Nimbus is not the current look and feel. It seems that
DerivedColor
looks up the current look and feel and then fails to decode the parent color.So the solution is to use copies of the default colors for the case that Nimbus is not set.