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. 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.
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开发者_JAVA百科 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); I'm not sure if there is an equivalent for SWT... Any help is greatly appreciated!
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). See CCombo snippet for details..
精彩评论