0
我有Table
它有SWT.CHECK
風格,所以我可以刪除選中的項目。我添加按鈕,SelectionAdapter
做的工作:org.eclipse.swt.SWTException:從表中刪除多行時部署Widget - SWT
Button btnRemove = new Button(this, SWT.PUSH);
btnRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] items = table.getItems(); /* get all items */
int i;
for (i = 0;i < items.length;i++)
if (items[i].getChecked()) /* look if it is selected */
table.remove(i);
}
});
當我刪除單個項目,它工作正常,但是當我檢查多個項目,然後點擊刪除,我得到SWTException: Widget is disposed
。以下是完整的堆棧跟蹤:
org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4282)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.SWT.error(SWT.java:4168)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
at org.eclipse.swt.widgets.TableItem.getChecked(TableItem.java:423)
at org.majid.swt.Main$1.widgetSelected(Main.java:132)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.majid.swt.Main.main(Main.java:24)
- 任何人都可以幫助解決這個問題?
- 有沒有像
TableItems[] getCheckedItems()
這樣的方法來檢索只檢查項目而不是檢查整個項目?