初始化时关闭 JFace 窗口
我有一个包含文件列表的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
Window
对象尚未获得窗口 shell,则open()
方法将创建一个新窗口并打开它。当调用createContents(Composite Parent)
时,它位于其create()
方法中,以及配置一些视觉细节的其他方法。这就是initializeBounds()
方法,它依赖于已经存在的 shell。如果你关闭它,你就得到了例外。也许您想覆盖
open()
方法本身:If the
Window
object hasn't got a window shell yet, theopen()
method creates a new one and opens it. It's in itscreate()
method whencreateContents(Composite parent)
is called upon, along with some other method which configure some visual details. That's theinitializeBounds()
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: