我已经在一列中实现了一个按钮小部件的SWT表。点击一个按钮,我将删除整行。但我不明白如何刷新/重绘/更新表。
Table processListTable;
TableItem tableItem;
Image deleteImage = Activator.getImageDescriptor("icons/trash.gif").createImage();
private void addRowInTable() {
tableItem = new TableItem(processListTable, SWT.FILL);
tableItem.setText(0, "value 1");
tableItem.setText(1, "value 2");
TableEditor editor = new TableEditor(processListTable);
final Button deleteButton = new Button(processListTable, SWT.PUSH | SWT.FILL);
deleteButton.pack();
editor.minimumWidth = deleteButtonButton.getSize().x;
editor.horizontalAlignment = SWT.CENTER;
editor.setEditor(deleteButtonButton, tableItem, 2);
deleteButtonButton.setImage(deleteImage);
deleteButtonButton.addListener(SWT.Selection, new SelectionListener(tableItem, checkButton));
}
class SelectionListener implements Listener {
TableItem item;
Button deleteButton;
public SelectionListener(TableItem item, Button deleteButton) {
this.item = item;
this.deleteButton = deleteButton;
}
public void handleEvent(Event event) {
this.deleteButton.dispose();
this.item.dispose();
}
}
答案 0 :(得分:4)
检查SWT代码段remove selected items from Table。
只需拨打table.remove(int rowIdx);
而不是item.dispose();
答案 1 :(得分:1)
将JFace TableViewer与模型类一起使用,从模型中删除对象并刷新TableViewer。
答案 2 :(得分:0)
public void handleEvent(Event event) {
this.deleteButton.dispose();
this.trash.dispose();
this.item .dispose();
Table table = viewer.getTable();
table.getColumn(2).pack();
table.getColumn(2).setWidth(100);
}
这是刷新SWT表的解决方案。