0

我对 JavaFX 了解不多,但我需要在 JFrame 中的 JPanel 上显示 WebView。这是我的代码

public class Ventana extends javax.swing.JFrame {


        JFXPanel jfxPanel = new JFXPanel();

        
    public Ventana() {
        initComponents();
        
        panel.add(jfxPanel);
        Platform.runLater(() -> {
            WebView webView = new WebView();
            jfxPanel.setScene(new Scene(webView));
            webView.getEngine().load("http://www.stackoverflow.com/");
        });
    }
}

这是我打开 jFrame 的主要方法

public static void main(String[] args) {
        
        Ventana jf_ventana = new Ventana();
        jf_ventana.setVisible(true);
        
    }

我使用的代码是这样说的

// 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/");
    });

它不会崩溃或任何东西,但也没有显示任何东西

4

0 回答 0