英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论