This discussion is archived
4 Replies Latest reply: Oct 9, 2012 12:13 PM by jrox RSS

Swing and JavaFX

jrox Newbie
Currently Being Moderated
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() {
               @Override
public void run() {
     stack.getChildren().add(text);
}
});
     }
  • 1. Re: Swing and JavaFX
    jrox Newbie
    Currently Being Moderated
    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 Newbie
    Currently Being Moderated
    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
    restenbro Newbie
    Currently Being Moderated
    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 {
    Platform.setImplicitExit(false);
    }
  • 4. Re: Swing and JavaFX
    jrox Newbie
    Currently Being Moderated
    That was exactly the problem. thank you guys!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points