1

Synth LaFを使用して、JLabelのFOREGROUNDカラーをDISABLED状態に設定できません。誰かがこれを行うことに成功しましたか?これが私の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ファイルで定義されている他のすべてのスタイルが、ラベルのWHITEの通常の状態の色を含め、アプリケーションで適切にレンダリングされることに注意してください(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に無効な色を設定する方法がわかりませんでした

ご協力いただきありがとうございます!

4

2 に答える 2

0

私はこの質問が古いことを知っていますが、誰かがまだ答えを必要としているかもしれません:

Synth L&F でテキストの色をカスタマイズするには、次のように色の種類を「TEXT_FOREGROUND」に設定する必要があります。

<state value="DISABLED">
    <color type="TEXT_FOREGROUND" value="BLACK"/>
</state>
于 2010-05-12T01:24:26.447 に答える
0

SynthStyle.getColor のソース コードがあなたのものとは異なることがわかりました (私のものは Sun JDK 1.5 のものです)。

/**
 * Returns the color for the specified state. This gives precedence to
 * foreground and background of the <code>JComponent</code>. If the
 * <code>Color</code> from the <code>JComponent</code> is not appropriate,
 * or not used, this will invoke <code>getColorForState</code>. Subclasses
 * should generally not have to override this, instead override
 * {@link #getColorForState}.
 *
 * @param context SynthContext identifying requester
 * @param type Type of color being requested.
 * @return Color
 */
public Color getColor(SynthContext context, ColorType type) {
    JComponent c = context.getComponent();
    Region id = context.getRegion();
    int cs = context.getComponentState();
    // For the enabled state, prefer the widget's colors
    if (!id.isSubregion() && cs == SynthConstants.ENABLED) {
        if (type == ColorType.BACKGROUND) {
            return c.getBackground();
        }
        else if (type == ColorType.FOREGROUND) {
            return c.getForeground();
        }
        else if (type == ColorType.TEXT_FOREGROUND) {
            // If getForeground returns a non-UIResource it means the
            // developer has explicitly set the foreground, use it over
            // that of TEXT_FOREGROUND as that is typically the expected
            // behavior.
            Color color = c.getForeground();
            if (!(color instanceof UIResource)) {
                return color;
            }
        }
    }
    // Then use what we've locally defined
    Color color = getColorForState(context, type);
    if (color == null) {
        // No color, fallback to that of the widget.
        if (type == ColorType.BACKGROUND ||
                    type == ColorType.TEXT_BACKGROUND) {
            return c.getBackground();
        }
        else if (type == ColorType.FOREGROUND ||
                 type == ColorType.TEXT_FOREGROUND) {
            return c.getForeground();
        }
    }
    return color;
}
于 2010-05-13T02:01:55.400 に答える