Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 262784 - Text.setBackground(null) does not correctly revert to the system default color
Summary: Text.setBackground(null) does not correctly revert to the system default color
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.4.1   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.17 M1   Edit
Assignee: Lakshmi P Shanmugam CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-28 11:21 EST by Micah Hainline CLA
Modified: 2020-07-07 05:12 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Micah Hainline CLA 2009-01-28 11:21:16 EST
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.
Comment 1 Felipe Heidrich CLA 2009-01-28 11:35:44 EST
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) ?
Comment 2 Micah Hainline CLA 2009-01-28 12:23:20 EST
(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

Comment 3 Silenio Quarti CLA 2009-01-28 13:09:32 EST
	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
Comment 4 Micah Hainline CLA 2009-01-28 13:48:15 EST
The version I used was Intel if that makes a difference, also OS X version 10.5.6
Comment 5 Silenio Quarti CLA 2012-06-21 12:56:06 EDT
There is still some problem with the background in the cocoa port. Foreground works fine.
Comment 6 Lakshmi P Shanmugam CLA 2020-06-25 09:22:49 EDT
I'm able to reproduce the problem with Text.setBackground(). The background changes, but only when the widget loses focus.
Comment 7 Lakshmi P Shanmugam CLA 2020-06-30 04:24:55 EDT
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();
	    }
	}
}
Comment 8 Eclipse Genie CLA 2020-06-30 04:47:50 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/165602
Comment 10 Lakshmi P Shanmugam CLA 2020-07-07 05:12:35 EDT
Verified with Build id: I20200706-2300