简体   繁体   English

Java SWT 当 combobox setEnabled() 为 false 时更改文本颜色

[英]Java SWT Changing text color when combobox setEnabled() is false

When I use the setEnabled() on comboboxes,(and its set to false) I'm wondering how I can change the text color so it is black and not gray.当我在组合框上使用 setEnabled()(并将其设置为 false)时,我想知道如何更改文本颜色,使其变为黑色而不是灰色。 The people I'm developing software for, and myself, find it too hard to read and I can't find a way to access the text color.我为之开发软件的人和我自己都觉得它太难阅读了,而且我找不到访问文本颜色的方法。 It was easy fixing text components as I just had to use setEditable() instead which did not gray the text color but there is not a setEditable() method available to comboboxes in SWT.修复文本组件很容易,因为我只需要使用 setEditable() 代替它不会使文本颜色变灰,但是 SWT 中的组合框没有可用的 setEditable() 方法。

To further clarify, I have tried to override the method, but it won't use my method, instead it uses the inherited method below...为了进一步澄清,我试图覆盖该方法,但它不会使用我的方法,而是使用下面的继承方法......

public void setEnabled (boolean enabled) {
    checkWidget ();
    /*
    * Feature in Windows.  If the receiver has focus, disabling
    * the receiver causes no window to have focus.  The fix is
    * to assign focus to the first ancestor window that takes
    * focus.  If no window will take focus, set focus to the
    * desktop.
    */
    Control control = null;
    boolean fixFocus = false;
    if (!enabled) {
        if (display.focusEvent != SWT.FocusOut) {
            control = display.getFocusControl ();
            fixFocus = isFocusAncestor (control);
        }
    }
    enableWidget (enabled);
    if (fixFocus) fixFocus (control);
}

I can't find the text painting code in here, and now I'm becoming a little more confused as I am somewhat more familiar with Swing which has the UIManager in which case it would look something like UIManager.put( "ComboBox.disabledText", Color.black);我在这里找不到文本绘制代码,现在我变得有点困惑,因为我对具有 UIManager 的 Swing 更加熟悉,在这种情况下,它看起来像 UIManager.put("ComboBox.disabledText “, 颜色:黑色); I'm not sure if there is an equivalent for SWT... Any help is greatly appreciated!我不确定是否有 SWT 的等价物......非常感谢任何帮助!

Color of disabled component is one of those things which depends on system, so it's not possible to change the color.禁用组件的颜色是依赖于系统的东西之一,因此无法更改颜色。

You can use CCombo instead, which is much more usable and have exactly your requirements (disabled have black color of text and the color could be set by setForeground method).您可以改用CCombo ,它更实用并且完全符合您的要求(禁用文本的黑色,颜色可以通过 setForeground 方法设置)。 See CCombo snippet for details..有关详细信息,请参阅CCombo 片段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM