I want to embed a dukescript app inside a Swing App so I think that I have to embed a panel to support JavaFX rendering.
final JFXPanel fxPanel = new JFXPanel();
Scene scene = createScene();
fxPanel.setScene(scene);
To be able to render Dukescript I think that I have to add a Webview so the alreasy existing JavaFX presenter (from html for java) can receive it an use it accordingly.
Group root = new Group();
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
root.getChildren().add(browser);
And then to use it with Dukescript I think that I should add maven dependency for JavaFx presenters.
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>net.java.html.boot.fx</artifactId>
<scope>runtime</scope>
</dependency>
So I think it the desired code should be something like that.
net.java.html.boot.fx.FXBrowsers presenter= new FXBrowsers();
presenter.load(browser ,
"index.html",
Runnable onPageLoad??);
Have you already tried it? Thank you in advance.
the leaflet4j Project has a demo of embedding DukeScript in JavaFX:
https://github.com/dukescript/leaflet4j
It should work the same in Swing, but you'll have to call the JavaFX code on the JavaFX EventQueue, similar to this:
Platform.runLater(new Runnable() {
@Override
public void run() {
webView = new WebView();
FXBrowsers.load(webView, this.getClass().getResource("/demo/test.html"),
new Runnable() {
@Override
public void run() {
try {
DataModel.onPageLoad();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
);