4 Replies Latest reply on Oct 9, 2012 7:13 PM by jrox

    Swing and JavaFX

      I'm using the JFXPanel in my Swing application and I'm running into problems when trying to update the content of that JFXPanel. The first time when the Frame gets initialized and the Scene gets instantiatet I can display a Text on the JFXPanel. But trying to change the Text later on by using Platform.runLater(...) does not throw an error but the content just does not get refreshed. What am I doing wrong?

      This is the method I'm calling from my Swing application with a new Text object. The Swing Panel is hidden and is shown again after this method call but the ui stays empty. "stack" is just a StackPane.

      public void setText(final Text text) {
                Platform.runLater(new Runnable() {
      public void run() {
        • 1. Re: Swing and JavaFX
          Okay to be more precise the problem comes up when I remove the JFXPanel and add it again. As part of the code the JFXPanel gets removed and added again, after that the text is updated but as I said the change is not visible. If I don't remove the JFXPanel and add it again the change on the JFXPanel is visible once more .... any idea?
          • 2. Re: Swing and JavaFX
            Jeff Martin
            Have you called Platform.setImplicitExit(false)? Although, I'd think a problem there manifests itself with an exception.

            Perhaps also make sure you call myjfxpanel.revalidate()/repaint().
            • 3. Re: Swing and JavaFX
              I think your problem may be that JavaFX "kills itself" when you exit the last window you have with JavaFX running in it. If you are running JavaFX within a Swing-based application (like Netbeans), this is probably not the same as exiting the application alltogether. However, the JavaFX thread shut down when you close the last JavaFX-window, and it will not start again if you reopen it. I've seen this happen with TopComponents in Netbeans applications, for example.

              JavaFX 2.2 added the setImplicitExit method to Platform that can suppress this behavior. It was not present before the 2.2 update. Be aware that you may need to invoke this method on the Swing thread rather than the JavaFX Application thread. Try adding this to your setup:

              SwingUtilities.invokeLater {
              • 4. Re: Swing and JavaFX
                That was exactly the problem. thank you guys!