Creating a JavaFX component inside a Swing App works only once

时间:2015-07-31 19:39:57

标签: javafx

I have a large Swing application in which I want to use some newer JavaFX components. In one case, I had a Swing JDialog which was being instantiated and shown, and in that Dialog I placed a JFXPanel() to host the JavaFX content.

The first time through the application, this worked fine, but coming back to the dialog a second time (during the same run of the application) all of my JavaFX content did not appear. No exceptions were thrown, just ... nothing happened.

1 个答案:

答案 0 :(得分:3)

I had thought initially that something was blocking the Platform.runLater() call I was making to build the JavaFX components, but now I think that the entire JavaFX platform silently killed itself and (more importantly) refused to come back when the parent dialog was called again.

Adding Platform.setImplicitExit(false) fixes the problem. I assume this is because, when the parent dialog closes, the only existing JavaFX stage (an EmbeddedWindow) also closes, which then terminates the JavaFX thread. I would have expected the subsequent calls to Platform or new JFXPanel() would have "reawoken" JavaFX but that does not appear to happen.