1

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.

Ruslan López
  • 4,433
  • 2
  • 26
  • 37

1 Answers1

2

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();
          }
        }
      });
    }
  }
);
monacotoni
  • 606
  • 5
  • 18
  • Thank you Mr. Epple It worked like a charm!. Now we can create plugins for Jetbrains IDEs based on dukescript technology. I'll create the tutorial soon. – Ruslan López May 05 '17 at 18:37