Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 292449

Summary: setBackgroundColor fails/delayed within Combo's ModifyListener trigger
Product: [Eclipse Project] Platform Reporter: ArronM <arronm>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: christian.campo, cocoakevin, elias, grant_gayed, lshanmug
Version: 3.6Keywords: triaged
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard: stalebug

Description ArronM CLA 2009-10-15 14:48:38 EDT
User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
Build Identifier: SWT3556b

calling setBackgroundColor within the ModifyListener trigger of a Combo does not set the background color until the control loses focus.  Works immediately on Windows, and in Carbon (last I checked).

Reproducible: Always

Steps to Reproduce:
Snippet: (type one character, the background should turn blue, type another, it should go back to default, etc.  On Cocoa, you have to type one character then tab to next field to get the blue)

	public static void main(String[] args) {
		final Display display = new Display();
		Shell shell = new Shell(display, SWT.SHELL_TRIM);
		shell.setLayout(new FillLayout(SWT.VERTICAL));

		final Combo combo = new Combo(shell, SWT.DROP_DOWN);
		combo.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				Color color = combo.getText().length() % 2 == 0 ? null
						: display.getSystemColor(SWT.COLOR_BLUE);
				combo.setBackground(color);
			}
		});
		
		Text btn = new Text(shell, SWT.PUSH);
		btn.setText("text to tab to");

		shell.open();
		combo.setFocus();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
Comment 1 Kevin Barnes CLA 2009-10-16 17:39:20 EDT
The field editor isn't getting the background color on 10.6 only. I tried forcing it, but didn't improve anything.
NSTextField has the same bug (ie Text with SWT.SINGLE).
Comment 2 Christian Campo CLA 2009-10-21 13:45:34 EDT
Here is a snippet to reproduce it with the Text widget:

public final class SnippetText001 {

	public static void main(String[] args) {
		Display display = Display.getDefault();
		try {
			Shell shell = new Shell();
			GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).spacing(20, 10).applyTo(shell);

			createLabel(shell, "Input (>5):"); //$NON-NLS-1$
			final Text text = new Text(shell, SWT.BORDER);
			GridDataFactory.fillDefaults().grab(true, false).applyTo(text);

			createLabel(shell, "Output:"); //$NON-NLS-1$
			Label label = createLabel(shell, ""); //$NON-NLS-1$
			GridDataFactory.fillDefaults().grab(true, false).applyTo(label);

			final Color oldBackground = text.getBackground();
			text.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));

			text.addModifyListener(new ModifyListener() {
				public void modifyText(ModifyEvent e) {
					if (text.getText().length() > 4) {
						text.setBackground(oldBackground);
					}
				}
			});

			Button button = new Button(shell, SWT.NONE);
			button.setText("click me");
			button.addSelectionListener(new SelectionListener() {
				public void widgetSelected(SelectionEvent e) {
					text.setBackground(oldBackground);
				}

				public void widgetDefaultSelected(SelectionEvent e) {
				}
			});

			shell.setSize(200, 200);
			shell.open();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} finally {
			display.dispose();
		}
	}

	private static Label createLabel(Shell shell, String caption) {
		Label result = new Label(shell, SWT.NONE);
		result.setText(caption);
		return result;
	}
}

When you run it, the Text starts with a yellow background and should become white when you have more than 5 chars or you press the click me button. Both work on windows but not on Mac OS X 10.6.
Comment 3 ArronM CLA 2017-06-21 18:49:20 EDT
Tested on 4801 on macOS Sierra 10.12.5 and bug still exists
Comment 4 Lakshmi P Shanmugam CLA 2017-07-03 00:36:38 EDT
Bug triaged, visit https://wiki.eclipse.org/SWT/Devel/Triage for more
information.
Comment 5 Eclipse Genie CLA 2020-03-21 13:17:59 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.