zoukankan      html  css  js  c++  java
  • SWT的SelectionEvent.stateMask不起作用

    通常理解stateMask的作用是标志事件发生时是否有Shift、Ctrl等键同时按下,但SWT里绝大多数Control都不支持这个标志,无论按下什么键,事件对象里的stateMask都是0(不信可以运行下面的代码)。更奇怪的是这个问题已经被提出3年多还没有解决,stateMask只对MenuItem有用,那要怎么实现对Button的Ctrl+Click检测呢?

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    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 ButtonTest {
    
     public static void main(String[] args) {
      Display display = new Display();
      Shell shell = new Shell(display);
      shell.setLayout(new GridLayout());
      shell.setSize(200, 200);
    
      final Button button = new Button(shell, SWT.NONE);
      button.addSelectionListener(new SelectionAdapter() {
       public void widgetSelected(SelectionEvent e) {
        System.out.println(e.stateMask);//Always zero
       }
      });
      button.setText("Test");
    
      shell.open();
      while (!shell.isDisposed()) {
       if (!display.readAndDispatch())
        display.sleep();
      }
      display.dispose();
     }
    }
  • 相关阅读:
    页面滚动
    代码提交报错
    校区下部门 及校区下员工
    表查询
    Jemeter命令执行
    抓包工具
    彻底解决mac下terminal路径显示问题
    PHP 性能分析第二篇: Xhgui In-Depth
    PHP 性能分析第一篇: Intro to Xhprof & Xhgui
    phpredis pipeline
  • 原文地址:https://www.cnblogs.com/bjzhanghao/p/873677.html
Copyright © 2011-2022 走看看