Community
Participate
Working Groups
Text.setForeground(Color) appears to have no effect when null is sent in as the color, and the previous color remains as the foreground. In the particular case I observe this, I set the foreground to white and the background to red when an error condition occurs, then set them both to null when the error condition is fixed. The background reverts to white, but the foreground remains white instead of reverting to black.
Sorry for adding kevin,grant,scott to this bug. I saw mac and automatically assumed it was cocoa. Micah: does it work with Eclipse 3.5 M4 (or newer) ?
(In reply to comment #1) > Micah: does it work with Eclipse 3.5 M4 (or newer) ? I have very limited access to Mac hardware, so I have not had the opportunity to check different versions. I actually made a mistake on the version number for the one I confirmed the problem on. It was 3.4.1, not 3.4.2
final Text text = new Text(shell, SWT.SINGLE); text.setText("text colored"); text.addListener(SWT.KeyDown, new Listener() { public void handleEvent(Event event) { if (event.keyCode == SWT.F1) { text.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); text.setBackground(display.getSystemColor(SWT.COLOR_RED)); } else if (event.keyCode == SWT.F2) { text.setForeground(null); text.setBackground(null); } } }); text.pack(); The foreground works for me, that fails is the background which gets reset to gray after calling setBackground(null). Note that multi-line text has the same problem. Plus the compute size include a vscroll that looks very ugly. my mac is ppc running 10.5.6
The version I used was Intel if that makes a difference, also OS X version 10.5.6
There is still some problem with the background in the cocoa port. Foreground works fine.
I'm able to reproduce the problem with Text.setBackground(). The background changes, but only when the widget loses focus.
Complete snippet based on comment#3: public class Snippet { public static void main(String[] args) { Display display = Display.getDefault(); Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setLayout(new RowLayout()); final Text text1 = new Text(shell, SWT.SINGLE|SWT.READ_ONLY); text1.setText("text colored"); text1.setBackground(display.getSystemColor(SWT.COLOR_RED)); text1.addListener(SWT.KeyDown, new Listener() { @Override public void handleEvent(Event event) { if (event.keyCode == SWT.F1) { text1.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); text1.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); } else if (event.keyCode == SWT.F2) { text1.setForeground(null); text1.setBackground(null); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/165602
Gerrit change https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/165602 was merged to [master]. Commit: http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=bd66337d94f520ad8cfd440f06b16a55006eafc1
Verified with Build id: I20200706-2300