java - 合成 LaF JLabel 禁用颜色

标签 java swing synth

使用 Synth LaF,我无法将 JLabel 的前景颜色设置为“禁用”状态。有人成功做到这一点吗?这是 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 设置禁用颜色

感谢您的帮助!

最佳答案

我知道这个问题已经很老了,但也许有人仍然需要答案:

要在 Synth L&F 中自定义文本颜色,您需要将颜色类型设置为“TEXT_FOREGROUND”,如下所示:

<state value="DISABLED">
    <color type="TEXT_FOREGROUND" value="BLACK"/>
</state>

关于java - 合成 LaF JLabel 禁用颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2014529/

相关文章:

java - 检索 java swing JFrame 图标

java - JFileChooser 关闭启动新窗口

java - 从 PNG 图像或 Java 面板创建 PDF

java - 当 List 实现的对象将其自己的对象存储为列表中的元素时,为什么 hashCode 和 equals 方法不起作用

java - 我的单选按钮没有与我的 JButton 交互

java - Synth 的 JPanel 状态

java - 任何人都可以帮助我通过改造从网络服务中获取数据吗?

java - 两条腿的 OAuth 和 Gmail Atom feed

java - Swing 字体渲染