* @param initializer Callback method to inizialize the pane further in the FX application thread.
* @return JFXPanel to be used in a Swing app
*/
public static JFXPanel createJFXPanel(final Pane pane, final PaneInitializer initializer) {
JuFxUtils.fxInitialized = true;
final JFXPanel fxPanel = new JFXPanel();
if (pane.getPrefWidth() > 0 && pane.getPrefHeight() > 0) {
fxPanel.setPreferredSize(new Dimension((int)pane.getPrefWidth(), (int)pane.getPrefHeight()));
}
/**
* Seems like we need to initialize the Scene later in the
* JavaFX thread:
* http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm#CHDIEEJE
*/
Platform.runLater(JuFxUtils.getFxWrapper(new Runnable() {
@Override
public void run() {
if (initializer != null) {
initializer.init(pane);
}
Scene scene = new Scene(pane);
fxPanel.setScene(scene);
}
}));
return fxPanel;
}