将按钮插入JFace表

far*_*day 2 swt jface

如何将SWT Button控件插入JFace TableViewer?

Kir*_*rby 12

给出的答案是一个很好的方法,可以在表格内外使用自定义绘图实现自己的按钮.但是,您可以将SWT控件放在JFace表中.

http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/PlacearbitrarycontrolsinaSWTtable.htm

使用链接提供的包含组合框,文本字段和按钮的列构建表的解决方案是:

Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
table.setLinesVisible(true);
for (int i = 0; i < 3; i++) {
  TableColumn column = new TableColumn(table, SWT.NONE);
  column.setWidth(100);
}
for (int i = 0; i < 12; i++) {
  new TableItem(table, SWT.NONE);
}
TableItem[] items = table.getItems();
for (int i = 0; i < items.length; i++) {
  TableEditor editor = new TableEditor(table);
  CCombo combo = new CCombo(table, SWT.NONE);
  editor.grabHorizontal = true;
  editor.setEditor(combo, items[i], 0);
  editor = new TableEditor(table);
  Text text = new Text(table, SWT.NONE);
  editor.grabHorizontal = true;
  editor.setEditor(text, items[i], 1);
  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);
}
Run Code Online (Sandbox Code Playgroud)