开发者

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

开发者 https://www.devze.com 2022-12-25 06:04 出处:网络
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 ver

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消