如何修复在尝试第二次打开 Shell 时出现小部件已释放错误?

huangapple go评论73阅读模式
英文:

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

问题

以下是您要翻译的内容:

当我尝试第二次打开子shell时,出现了小部件已释放的错误。
我尝试创建一个主Shell,并带有菜单栏,然后为功能创建子shell。

以下是打印堆栈跟踪:

org.eclipse.swt.SWTException: 小部件已释放
在 org.eclipse.swt.SWT.error(未知来源)
在 org.eclipse.swt.SWT.error(未知来源)
在 org.eclipse.swt.SWT.error(未知来源)
在 org.eclipse.swt.widgets.Widget.error(未知来源)
在 org.eclipse.swt.widgets.Widget.checkWidget(未知来源)
在 org.eclipse.swt.widgets.Shell.close(未知来源)
在 it.anabasibdg.viste.Main$2.widgetSelected(Main.java:108)
在 org.eclipse.swt.widgets.TypedListener.handleEvent(未知来源)
在 org.eclipse.swt.widgets.EventTable.sendEvent(未知来源)
在 org.eclipse.swt.widgets.Widget.sendEvent(未知来源)
在 org.eclipse.swt.widgets.Display.runDeferredEvents(未知来源)
在 org.eclipse.swt.widgets.Display.readAndDispatch(未知来源)
在 it.anabasibdg.viste.Main.open(Main.java:51)
在 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();
        }
    }
});
英文:

When I'm trying to open for the second time a child-shell, occur Widget is disposed error.
I'm trying to create a main Shell and, with menu-bar then child-shell for the functions.

Here the 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$2.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)

Here the code:

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

答案1

得分: 0

一旦 Shell 被关闭,Shell 及其包含的所有控件都会被销毁,不能再次使用。

每次想要使用它时,都必须从头开始创建新的 Shell 及其所有内容。

英文:

Once a Shell has been closed the Shell and all the controls it contains are disposed and can't be used again.

You must create a new shell and all its contents from scratch each time you want to use it.

huangapple
  • 本文由 发表于 2020年4月7日 17:29:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/61076837.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定