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

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

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

问题

以下是您要翻译的内容:

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

以下是打印堆栈跟踪:

  1. org.eclipse.swt.SWTException: 小部件已释放
  2. org.eclipse.swt.SWT.error(未知来源)
  3. org.eclipse.swt.SWT.error(未知来源)
  4. org.eclipse.swt.SWT.error(未知来源)
  5. org.eclipse.swt.widgets.Widget.error(未知来源)
  6. org.eclipse.swt.widgets.Widget.checkWidget(未知来源)
  7. org.eclipse.swt.widgets.Shell.close(未知来源)
  8. it.anabasibdg.viste.Main$2.widgetSelected(Main.java:108)
  9. org.eclipse.swt.widgets.TypedListener.handleEvent(未知来源)
  10. org.eclipse.swt.widgets.EventTable.sendEvent(未知来源)
  11. org.eclipse.swt.widgets.Widget.sendEvent(未知来源)
  12. org.eclipse.swt.widgets.Display.runDeferredEvents(未知来源)
  13. org.eclipse.swt.widgets.Display.readAndDispatch(未知来源)
  14. it.anabasibdg.viste.Main.open(Main.java:51)
  15. it.anabasibdg.viste.Main.main(Main.java:36)

以下是代码:

  1. MenuItem mntmInserimento = new MenuItem(menu_2, SWT.NONE);
  2. mntmInserimento.addSelectionListener(new SelectionAdapter() {
  3. @Override
  4. public void widgetSelected(SelectionEvent e) {
  5. if (cs1.isDisposed() == false) {
  6. cs1.layout();
  7. cs1.open();
  8. } else {
  9. cs1.open();
  10. }
  11. }
  12. });
英文:

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:

  1. org.eclipse.swt.SWTException: Widget is disposed
  2. at org.eclipse.swt.SWT.error(Unknown Source)
  3. at org.eclipse.swt.SWT.error(Unknown Source)
  4. at org.eclipse.swt.SWT.error(Unknown Source)
  5. at org.eclipse.swt.widgets.Widget.error(Unknown Source)
  6. at org.eclipse.swt.widgets.Widget.checkWidget(Unknown Source)
  7. at org.eclipse.swt.widgets.Shell.close(Unknown Source)
  8. at it.anabasibdg.viste.Main$2.widgetSelected(Main.java:108)
  9. at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
  10. at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
  11. at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
  12. at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
  13. at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
  14. at it.anabasibdg.viste.Main.open(Main.java:51)
  15. at it.anabasibdg.viste.Main.main(Main.java:36)

Here the code:

  1. MenuItem mntmInserimento = new MenuItem(menu_2, SWT.NONE);
  2. mntmInserimento.addSelectionListener(new SelectionAdapter() {
  3. @Override
  4. public void widgetSelected(SelectionEvent e) {
  5. if(cs1.isDisposed() == false) {
  6. cs1.layout();
  7. cs1.open();
  8. }else {
  9. cs1.open();
  10. }
  11. }
  12. });

答案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:

确定