2011-06-30 56 views
3

当我在组合框上使用setEnabled()(并将其设置为false)时,我想知道如何更改文本颜色,使其为黑色而不是灰色。我正在为自己开发软件的人和我自己发现,阅读起来太难,我无法找到访问文本颜色的方式。这很容易修复文本组件,因为我只需要使用setEditable(),而不是灰色的文本颜色,但没有setEditable()方法可用于SWT中的组合框。Java SWT当组合框setEnabled()为false时更改文本颜色

为了进一步澄清,我试图覆盖的方法,但它不会用我的方法,而是使用下面的继承的方法...

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

我找不到文字画代码在这里,现在我变得更加困惑,因为我更熟悉Swing,它具有UIManager ,在这种情况下,它将看起来像UIManager.put(“ComboBox.disabledText”,Color.black);我不确定是否有相当于SWT ...任何帮助,非常感谢!

回答

3

禁用组件的颜色是依赖于系统的事物之一,因此无法更改颜色。

您可以使用CCombo来代替,它更加可用并且完全符合您的要求(禁用了文本的黑色,并且可以通过setForeground方法设置颜色)。详情请见CCombo snippet ..