Ajouter le contrôle WebView sur Swing JFrame

je travaille sur l'application Swing mélangée avec JavaFX control.

j'ai créé un contrôle JavaFX ( WebView ) pour parcourir les fichiers HTML. Mais je veux pour savoir, comment puis-je ajouter ce contrôle web view sur le conteneur D'un Swing JFrame ?

15
demandé sur Andrew Thompson 2012-11-21 10:46:11

2 réponses

avec un jFrame déjà existant, le code suivant ajoute un nouveau WebView et charge une URL:

// You should execute this part on the Event Dispatch Thread
// because it modifies a Swing component 
JFXPanel jfxPanel = new JFXPanel();
jFrame.add(jfxPanel);

// Creation of scene and future interactions with JFXPanel
// should take place on the JavaFX Application Thread
Platform.runLater(() -> {
    WebView webView = new WebView();
    jfxPanel.setScene(new Scene(webView));
    webView.getEngine().load("http://www.stackoverflow.com/");
});
19
répondu heenenee 2016-02-05 16:48:04

JFXPanel vous permet d'intégrer JavaFX dans votre application Swing.

4
répondu Emily Crutcher 2015-02-09 15:52:07