初始化时关闭 JFace 窗口

发布于 2024-11-24 13:55:26 字数 729 浏览 0 评论 0原文

我有一个包含文件列表的 JFace 应用程序。当用户单击列表中的文件时,将打开一个子窗口。子窗口自动将文件内容加载到文本小部件中。

文件内容加载可能会失败。我可以检测到这种情况,并且我很乐意在子窗口显示在屏幕上之前关闭它。

我尝试在子窗口的重写 protected Control createContents(Composite Parent) 方法的末尾调用 close() 。但我在 JFace 库中的某处遇到了 null 异常:

Exception occurred java.lang.NullPointerException
at org.eclipse.jface.window.Window.initializeBounds(Window.java:758)
at org.eclipse.jface.window.Window.create(Window.java:435)
at org.eclipse.jface.window.Window.open(Window.java:790)

Where is a right place to initialize the window widgets with initial value?理想情况下,我认为它应该满足条件:

  • 小部件应该已经由框架创建。
  • 该窗口应该还不可见。
  • 如果需要,close() 应正确关闭窗口。

I have a JFace application with a list of files. A child window is opened when a user clicked on a file in the list. The child window automatically loads the file content into a Text widget.

Loading of the file content may fail. I can detect such a situation and I would be happy to close the child window before it is shown on the screen.

I tried to call close() at the end of overriden protected Control createContents(Composite parent) method of the child window. But I got a null exception somewhere in the JFace library:

Exception occurred java.lang.NullPointerException
at org.eclipse.jface.window.Window.initializeBounds(Window.java:758)
at org.eclipse.jface.window.Window.create(Window.java:435)
at org.eclipse.jface.window.Window.open(Window.java:790)

Where is a correct place to initialize the window widgets with initial values? Ideally I feel it should meet the conditions:

  • Widgets should be already created by the framework.
  • The window should not be visible yet.
  • close() should close the window correctly if needed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2024-12-01 13:55:26

如果 Window 对象尚未获得窗口 shell,则 open() 方法将创建一个新窗口并打开它。当调用 createContents(Composite Parent) 时,它位于其 create() 方法中,以及配置一些视觉细节的其他方法。这就是 initializeBounds() 方法,它依赖于已经存在的 shell。如果你关闭它,你就得到了例外。

也许您想覆盖 open() 方法本身:

public int open() {
   if (!condition)
        return super.open();    // as usual
    else
        return CANCEL;
}

If the Window object hasn't got a window shell yet, the open() method creates a new one and opens it. It's in its create() method when createContents(Composite parent) is called upon, along with some other method which configure some visual details. That's the initializeBounds() method, which relies on an already existing shell. If you close it, there you go, you got the exception.

Maybe you would want to overwrite the open() method itself:

public int open() {
   if (!condition)
        return super.open();    // as usual
    else
        return CANCEL;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文