Java SWT:如何删除 SWT 表中选定的行
我已经实现了一个 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();
}
}
I have implemented one SWT table having a button widget in one column. On click of a button I am deleting the entire row. But I don't understand how to refresh/redraw/update the table.
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查 SWT 代码段 从表中删除所选项目。
只需调用
table.remove(int rowIdx);
而不是item.dispose();
Check SWT snippet remove selected items from Table.
Just call
table.remove(int rowIdx);
instead ofitem.dispose();
这是刷新SWT表的解决方案。
This is the solution for refresh the SWT table.
将 JFace TableViewer 与模型类一起使用,从模型中删除对象并刷新 TableViewer。
Use the JFace TableViewer with a model class, delete the object from the model and refresh the TableViewer.