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();
     }
    }
  • 相关阅读:
    Day1-CSS-下拉菜单
    scau 1138 代码等式
    SCAU-1076 K尾相等数
    勾股数专题-SCAU-1079 三角形-18203 神奇的勾股数(原创)
    SCAU-1144 数星星-HDU-1166-树状数组的应用
    NodeJs Fs模块
    Node核心模块
    flutter环境配置
    纯CSS制作图形效果
    CSS3选择器
  • 原文地址:https://www.cnblogs.com/bjzhanghao/p/873677.html
Copyright © 2011-2022 走看看