SWT: problems with clicking button after using setEnabled() on Linux
- by Laimoncijus
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