当前位置: 首页>>代码示例>>Java>>正文


Java JTextComponent.getDisabledTextColor方法代码示例

本文整理汇总了Java中javax.swing.text.JTextComponent.getDisabledTextColor方法的典型用法代码示例。如果您正苦于以下问题:Java JTextComponent.getDisabledTextColor方法的具体用法?Java JTextComponent.getDisabledTextColor怎么用?Java JTextComponent.getDisabledTextColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.JTextComponent的用法示例。


在下文中一共展示了JTextComponent.getDisabledTextColor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: paint

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void paint(Graphics g, Shape a) {
    ((Graphics2D) g).addRenderingHints(getHints());

    Container container = getContainer();
    if (container instanceof JTextComponent) {
        final JTextComponent textComp = (JTextComponent) container;
        selStart = textComp.getSelectionStart();
        selEnd = textComp.getSelectionEnd();
        unselectedFg = textComp.isEnabled()
                ? textComp.getForeground()
                : textComp.getDisabledTextColor();
        selectedFg = textComp.getCaret().isSelectionVisible()
                ? textComp.getSelectedTextColor()
                : unselectedFg;
    }
    super.paint(g, a);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:OutputView.java

示例2: getColor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * 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();

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

    // If the developer has specified a color, prefer it. Otherwise, get
    // the color for the state.
    Color color = null;
    if (!id.isSubregion()) {
        if (type == ColorType.BACKGROUND) {
            color = c.getBackground();
        }
        else if (type == ColorType.FOREGROUND) {
            color = c.getForeground();
        }
        else if (type == ColorType.TEXT_FOREGROUND) {
            color = c.getForeground();
        }
    }

    if (color == null || color instanceof UIResource) {
        // Then use what we've locally defined
        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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:71,代码来源:SynthStyle.java

示例3: getColor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * 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();

    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 || c instanceof JMenuItem) &&
                        (type == ColorType.FOREGROUND ||
                         type == ColorType.TEXT_FOREGROUND)) {
            return getColorForState(context, type);
        }
    }

    // If the developer has specified a color, prefer it. Otherwise, get
    // the color for the state.
    Color color = null;
    if (!id.isSubregion()) {
        if (type == ColorType.BACKGROUND) {
            color = c.getBackground();
        }
        else if (type == ColorType.FOREGROUND) {
            color = c.getForeground();
        }
        else if (type == ColorType.TEXT_FOREGROUND) {
            color = c.getForeground();
        }
    }

    if (color == null || color instanceof UIResource) {
        // Then use what we've locally defined
        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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:71,代码来源:SynthStyle.java


注:本文中的javax.swing.text.JTextComponent.getDisabledTextColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。