Anakin001 Anakin001 - 4 months ago 22
Java Question

JavaFX Platform seems to be dead (closed/crashed)

My use case is the following:


  • I have a GridBagLayout with 9 rows and 1 column

  • First 8 rows contain JPanels

  • Last row contains a JFXPanel (used to display html, called htmlPanel in the code below)

  • I want to switch the JFXPanel with any of the JPanels



I do something like:

if(htmlToFront){
gridBagConstraints.gridy = i - 1;
}
else{
gridBagConstraints.gridy = 8;
}
jPanel1.add(htmlPanel, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
//some other gridbag initializations
if(htmlToFront){
gridBagConstraints.gridy = 8;
}
else{
gridBagConstraints.gridy = i - 1;
}
jPanel1.add(jPanel, gridBagConstraints);


The switch is done properly - the JFXPanel and JPanel are in their proper places. But the scene is not shown anymore after a few switches. I mean, after one or two switches everything is ok, my html code inside the htmlPanel is shown properly. But after another couple of switches (and I wait some seconds before making a switch) the html code is not shown anymore.

I did some testing and it seems that Platform.runLater never calls any Runnable object after this problem occurs. It's like it is stuck on another job and I guess this is related to the fact that the html code is not shown (or maybe the platform is closed, but I don't know how to check this or why it would close).

Why does this happen? Maybe the way I do the switch is not good? Is there a problem with the fact that for some miliseconds during the switch the JFXPanel is not displayable?

A more general question would be why Platform.runLater doesn't do anything?

Answer

When you switch the panes there is a small space of time when the no FX nodes are part of a displayed scene graph. My guess is that if the FX Application Thread happens to process a scene pulse at this time, it detects there is no active scene graph and exits.

You can prevent this behavior with a call to

Platform.setImplicitExit(false);

immediately after creating the JFXPanel.