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

Bug 290166

Summary: [Widgets] Label.setImage within a MouseDown event prevents a MouseUp Event
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: albert.pikus, lshanmug, milesparker, skovatch, tamar.e.cohen
Version: 3.5Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard: stalebug

Description ArronM CLA 2009-09-22 14:29:18 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: SWT3555

Mac Cocoa SWT, calling Label.setImage within a MouseDown event prevents a MouseUp Event from being fired

Reproducible: Always

Steps to Reproduce:
snippet:

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

		final Button checkbox = new Button(shell, SWT.CHECK);
		checkbox.setSelection(true);
		checkbox.setText("SetImage in MouseDown");
		
		final Label label = new Label(shell, SWT.NONE);
		label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
		label.setText("Click Me");

		label.addListener(SWT.MouseDown, new Listener() {
			public void handleEvent(Event event) {
				System.out.println("Mouse Down");

				// This prevents MouseUp from firing
				if (checkbox.getSelection()) {
					label.setImage(null);
				}
			}
		});

		label.addListener(SWT.MouseUp, new Listener() {
			public void handleEvent(Event event) {
				System.out.println("Mouse Up");
			}
		});

		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
Comment 1 Scott Kovatch CLA 2009-10-27 13:27:31 EDT
This happens if you call Label.setText() during mouse down, too. Calling setContentView is the culprit. If I add a check to not call setContentView if the imageView/textView is already the content view, the problem goes away, but if you switch the label from text to image or vice-versa, it won't fix the problem.
Comment 2 Miles Parker CLA 2011-09-01 13:15:46 EDT
(In reply to comment #1)
> This happens if you call Label.setText() during mouse down, too. Calling
> setContentView is the culprit. If I add a check to not call setContentView if
> the imageView/textView is already the content view, the problem goes away, but
> if you switch the label from text to image or vice-versa, it won't fix the
> problem.

I just ran into this as well. This seems to me to be a bad bug as it fails silently and is really difficult to diagnose. One doesn't usually suspect a deep SWT bug in this case, so I spent a lot of time digging around in my own code to try to discover what I did wrong.

Scott, can you describe a bit more about your work-around?
Comment 3 Albert Pikus CLA 2012-03-23 04:57:12 EDT
Hi,

I'm also experiencing this problem on Mac. Since I'm not changing Label's image to text or vice-versa, I just need to change an image on MouseDown event, I wonder what is the actual workaround.

Scott, is there any SWT patch for this?

Best regards,

Albert
Comment 4 Tamar Cohen CLA 2012-05-09 13:47:03 EDT
I worked around this problem by using a Canvas instead of a label, and just drawing the image and text with the gc.
Comment 5 Albert Pikus CLA 2012-05-10 03:21:24 EDT
(In reply to comment #4)
> I worked around this problem by using a Canvas instead of a label, and just
> drawing the image and text with the gc.

Thank you for your suggestion, this solution works for me too.
Comment 6 Lakshmi P Shanmugam CLA 2017-07-03 07:46:27 EDT
Bug triaged, visit https://wiki.eclipse.org/SWT/Devel/Triage for more
information.
Comment 7 Eclipse Genie CLA 2020-06-02 08:42:28 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.