在SWT的table中或在JFace的TableViewer中添加checkbox

(1)如果是在第一列,则可以使用SWT.CHECK 样式来实现,例如:

       Table table = new Table(parent, SWT.CHECK);

(2)如果不是第一列,则可以使用TableEditor,创建一个Control悬浮在CellEditor之上,例如:

       TableEditor editor = new TableEditor(table);
       Button button = new Button(table, SWT.CHECK);
       button.pack();
       editor.minimumWidth = button.getSize().x;
       editor.horizontalAlignment = SWT.LEFT;
       editor.setEditor(button, items[i], 2);

Demo连接:

http://www.java2s.com/Tutorial/Java/0280__SWT/TableCellEditorComboTextandButton.htm

posted @ 2012-10-15 23:12  finalstar  阅读(3958)  评论(0编辑  收藏  举报