SWT: problems with clicking button after using setEnabled() on Linux

Posted by Laimoncijus on Stack Overflow See other posts from Stack Overflow or by Laimoncijus
Published on 2010-03-30T11:31:04Z Indexed on 2010/03/30 11:33 UTC
Read the original article Hit count: 348

Filed under:
|
|
|
|

Hi,

I have a strange case with SWT and Button after using setEnabled() - seems if I disable and enable button at least once - I cannot properly click with mouse on it anymore... Already minify code to very basic:

import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell;

public class TestButton {

public TestButton() { Display display = new Display(); Shell shell = new Shell(display); GridLayout mainLayout = new GridLayout(); shell.setLayout(mainLayout); shell.setSize(100, 100);

Button testButton = new Button(shell, SWT.PUSH); testButton.addSelectionListener(new TestClickListener()); testButton.setText("Click me!"); //testButton.setEnabled(false); //testButton.setEnabled(true);

shell.open();

while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }

class TestClickListener implements SelectionListener {

@Override public void widgetDefaultSelected(SelectionEvent e) { }

@Override public void widgetSelected(SelectionEvent e) { System.out.println("Click!"); } }

public static void main(String[] args) { new TestButton(); }

}

When I keep these 2 lines commented out - I can properly click on a button and always get "Click!" logged, but if I uncomment them - then I can't click on button properly with mouse anymore - button visually seems to be clicked, but nothing is logged...

Am I doing something wrong here? Or maybe it's some kind of bug on Linux platform? Because on Mac running the same code I never experienced such problems...

Thanks for any hint!

P.S. Running code on Ubuntu 9.10, Gnome + Compiz, Sun Java 1.6.0.16

© Stack Overflow or respective owner

Related posts about java

Related posts about swt