简体   繁体   English

org.eclipse.swt.SWTException:从表中删除多行时会丢弃小部件-SWT

[英]org.eclipse.swt.SWTException: Widget is disposed when removing multiple rows from table - SWT

I have Table which has SWT.CHECK style so I can remove checked items. 我有具有SWT.CHECK样式的Table ,因此可以删除选中的项目。 I add button and SelectionAdapter to do the job: 我添加按钮和SelectionAdapter来完成这项工作:

    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);
        }
    });

When I remove single item, it is working fine, but when I check multiple items and then hit remove, I get SWTException: Widget is disposed . 当我删除单个项目时,它工作正常,但是当我检查多个项目然后点击删除时,我得到了SWTException: Widget is disposed Here is the full stack trace: 这是完整的堆栈跟踪:

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)
  1. Could anyone help with this problem? 有人可以帮助解决这个问题吗?
  2. Is there any method like TableItems[] getCheckedItems() to retrieve only check items instead of checking whole items? 是否有像TableItems[] getCheckedItems()来仅检索检查项目而不是检查整个项目?

Once you call table.remove(i); 一旦调用table.remove(i); the items in the table will be different (one less) than in your array and in the next iteration the i-th item in the table is not what you expect. 表中的项目将与数组中的项目不同(少一个),并且在下一次迭代中,表中的第i个项目不是您所期望的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.eclipse.swt.SWTException:从表刷新中“处理小部件” - org.eclipse.swt.SWTException: “Widget is disposed” from table refresh org.eclipse.swt.SWTException:尝试打开 AndroidManifest.xml 时出现“小部件已处理” - org.eclipse.swt.SWTException: “Widget is disposed” when trying to open AndroidManifest.xml 运行jar时的SWT异常:线程“main”中的异常org.eclipse.swt.SWTException:无效的线程访问 - SWT Exception when running jar: Exception in thread “main” org.eclipse.swt.SWTException: Invalid thread access org.eclipse.swt.SWTException: 无法执行 runnable - org.eclipse.swt.SWTException: Failed to execute runnable org.eclipse.swt.SWTException:无效的线程访问 - org.eclipse.swt.SWTException: Invalid thread access org.eclipse.swt.SWTException:不支持的颜色深度 - org.eclipse.swt.SWTException: Unsupported color depth org.eclipse.swt.SWTException:执行功能时Eclipse Graphiti中的图形 - org.eclipse.swt.SWTException: Graphic in Eclipse Graphiti when executing feature org.eclipse.swt.SWTException:无法执行可运行(java.lang.NullPointerException) - org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException) 从Eclipse RCP 3.x升级到4.x:org.eclipse.e4.core.di.InjectionException:org.eclipse.swt.SWTException:无效的线程访问 - Upgraded from Eclipse RCP 3.x to 4.x: org.eclipse.e4.core.di.InjectionException: org.eclipse.swt.SWTException: Invalid thread access SWT TreeViewer拖移n放下:放置SWTException小部件 - SWT TreeViewer Drag n Drop: SWTException Widget is disposed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM