Java SWT selection or check event in a table

2019-08-09 00:00:00 selection java swt

SWT获取表格前设置的复选框的选中状态

如下图

《Java SWT selection or check event in a table》

获取选中的值的代码如下

         table.addListener(SWT.Selection, new Listener() {
              public void handleEvent(Event event) {
                  if(event.detail == SWT.CHECK) {
                      String temp = Pattern.compile("[^0-9]").matcher(event.item.toString()).replaceAll("");
                      Integer select = Integer.parseInt(temp);
                      if(selectList.contains(select)) {
                          selectList.remove(select);
                      }else {
                          selectList.add(select);
                      }
                      for(int i=0; i<selectList.size(); i++) {
                          System.out.print(selectList.get(i));
                      }
                      System.out.println();
                  }
              }
          });

部分官方的样例

    table.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        String string = event.detail == SWT.CHECK ? "Checked"
            : "Selected";
        System.out.println(event.item + " " + string);
      }
    });

 

相关文章