2011-06-30 57 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 ..