第二次尝试打开 Shell 时,如何修复 Widget is disposed 错误?

How to fix Widget is disposed errer when tryng to open Shell for the second time?

当我第二次尝试打开child-shell时,出现Widget is disposed错误。 我正在尝试创建一个主 Shell,然后使用菜单栏和子 shell 来实现这些功能。

这里是 printStackTrace:

org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Widget.error(Unknown Source)
at org.eclipse.swt.widgets.Widget.checkWidget(Unknown Source)
at org.eclipse.swt.widgets.Shell.close(Unknown Source)
at it.anabasibdg.viste.Main.widgetSelected(Main.java:108)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at it.anabasibdg.viste.Main.open(Main.java:51)
at it.anabasibdg.viste.Main.main(Main.java:36)

这里是代码:

MenuItem mntmInserimento = new MenuItem(menu_2, SWT.NONE);
    mntmInserimento.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            if(cs1.isDisposed() == false) {


            cs1.layout();
            cs1.open();




        }else {

            cs1.open();



        }
    }
        });

一旦 Shell 关闭,Shell 及其包含的所有控件都将被处理掉并且不能再次使用。

您必须在每次要使用它时从头开始创建一个新的 shell 及其所有内容。