Project: SWT
Bug 72342 MouseListener behaving incorrectly when attached to Button
Reported: 2004-08-20 09:03:02 | Status: resolved fixed

import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.*; public class MouseBug implements MouseListener { public static void main(String[] args) { Display display = Display.getDefault(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setSize(100,100); MouseBug mousebug = new MouseBug(); // doesn't work under OS X: // mouse pressed: nothing happens // mouse released: mouse down event generated // double click: works Button button = new Button(shell, SWT.NONE); button.addMouseListener(mousebug); // works correctly under OS X Canvas canvas = new Canvas(shell, SWT.NONE); canvas.addMouseListener(mousebug); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } public void mouseDoubleClick(MouseEvent arg0) { System.out.println("mouse double click"); } public void mouseDown(MouseEvent arg0) { System.out.println("mouse down"); } public void mouseUp(MouseEvent arg0) { System.out.println("mouse up"); } }

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Button.java