SWT: problems with clicking button after using setEnabled() on Linux
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.dispo开发者_如何学Pythonse();
    }
    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
Or maybe it's some kind of bug on Linux platform?
Well using a recent version of eclipse, which use SWT, on Linux, some dialog have button on which a click do nothing. Maybe you ran into the same thing. This is worked around by specifying GDK_NATIVE_WINDOWS=1 in the environment variable, when launching eclipse.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论