使用 Synth LaF,我无法为 DISABLED 状态设置 JLabel 的 FOREGROUND 颜色。有没有人成功做到这一点?这是我的 LaF.xml 文件中标签的样式定义。
<style id="whiteLabelStyle">
<opaque value="false"/>
<font name="Bitstream Vera Sans" size="16" />
<state>
<color type="FOREGROUND" value="WHITE"/>
</state>
<state value="DISABLED">
<color type="FOREGROUND" value="BLACK"/>
</state>
</style>
<bind style="whiteLabelStyle" type="name" key="WhiteOrbitLabel"/>
请不要让我的 LaF.xml 文件中定义的所有其他样式在我的应用程序中正确呈现,包括我的标签的白色正常状态颜色(当我执行 lbl.setEnabled(false) 时它永远不会变黑
另外,通过 Synth 代码,我在 SynthStyle.getColor 中找到了以下注释
if ((context.getComponentState() & SynthConstants.DISABLED) != 0) {
//This component is disabled, so return the disabled color.
//In some cases this means ignoring the color specified by the
//developer on the component. In other cases it means using a
//specified disabledTextColor, such as on JTextComponents.
//For example, JLabel doesn't specify a disabled color that the
//developer can set, yet it should have a disabled color to the
//text when the label is disabled. This code allows for that.
if (c instanceof JTextComponent) {
JTextComponent txt = (JTextComponent)c;
Color disabledColor = txt.getDisabledTextColor();
if (disabledColor == null || disabledColor instanceof UIResource) {
return getColorForState(context, type);
}
} else if (c instanceof JLabel
&& (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND)){
return getColorForState(context, type);
}
但我不知道如何为 JLabel 设置禁用颜色
谢谢你的帮助!