简体   繁体   English

结束Swing应用程序时出现JavaFX错误

[英]JavaFX error when ending Swing application

I have a Swing application in which I need to display internally generated HTML/CSS. 我有一个Swing应用程序,需要在其中显示内部生成的HTML / CSS。 In order to do this, I have adapted the code from this StackOverflow question . 为了做到这一点,我改编了这个StackOverflow问题中的代码

The control works fine. 该控件工作正常。 However, when the application ends, I receive the error 但是,当应用程序结束时,我收到错误消息

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f9622171ae8, pid=5782, tid=140283095549696

For what it's worth, the sample code directly from Oracle (quoted in the StackOverflow post) has the same problem. 就其价值而言,直接来自Oracle的示例代码(在StackOverflow帖子中引用)具有相同的问题。

I have tried explicitly calling Platform.exit() when the window closes, but the error remains. 我已尝试在窗口关闭时显式调用Platform.exit() ,但错误仍然存​​在。 So, how does one shut down JavaFX correctly, when it is embedded in a Swing application? 那么,当JavaFX嵌入到Swing应用程序中时,如何正确关闭它呢?

Ok, I found the solution, at least for this application: 好的,至少在此应用程序中,我找到了解决方案:

  • This is a multi-window application; 这是一个多窗口应用程序; the JavaFX component is not in the main application window, but in a sub-window. JavaFX组件不在主应用程序窗口中,而是在子窗口中。

  • The JavaFX "Platform" has a setting "ImplicitExit", which is by default "true". JavaFX“平台”的设置为“ ImplicitExit”,默认情况下为“ true”。

  • JavaFX Platform.exit() is apparently called both when the sub-window is closed, and when the main application is closed. 显然,在关闭子窗口时和在关闭主应用程序时都将调用JavaFX Platform.exit()。 This second call (when the application is closed) generates the error message described in the original question. 第二个调用(当应用程序关闭时)生成原始问题中描述的错误消息。

  • The "implicit exit" behavior is in any case undesirable, because it prevents the sub-window from being re-opened a second time during the application's lifetime. 在任何情况下,“隐式退出”行为都是不可取的,因为它阻止了在应用程序的生命周期中再次打开子窗口。

Hence, the solution is to turn off "implicit exit". 因此,解决方案是关闭“隐式出口”。 Here's the JavaFX initialization code in the subwindow: 这是子窗口中的JavaFX初始化代码:

Platform.runLater(new Runnable() {
    @Override public void run() {
        view = new WebView();
        engine = view.getEngine();
        jfxPanel.setScene(new Scene(view));
        Platform.setImplicitExit(false); // Otherwise cannot open report window a second time
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM