JavaFX : Embedding a browser other than available webview with JavaFX

前端 未结 2 755
执念已碎
执念已碎 2021-02-19 21:00

I am working on a JavaFX application which contains few html,css,JS files which are rendered by the internal webkit browser. Now, the problem is the CSS animations which we have

2条回答
  •  醉梦人生
    2021-02-19 21:35

    Try using Java 8u112, based in your code I created a working sample (Tested using Java JDK 8u112 64bit):

    import javafx.application.Application;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.scene.web.WebEngine;
    import javafx.scene.web.WebView;
    import javafx.stage.Stage;
    
    public class Example extends Application
    {
        public static void main(String[] args)
        {
            launch(args);
        }
    
        class MyBrowser extends Parent
        {
            private WebEngine   webEngine;
            private WebView webView;
    
            public MyBrowser()
            {
                webView = new WebView();
                webEngine = webView.getEngine();
    
                // Ugly (but easy to share) HTML content 
                String pageContents = 
                        ""
                            + ""
                                + ""
                            + ""
                            + ""
                                + "
    " + "" + ""; webEngine.loadContent(pageContents); webView.setContextMenuEnabled(false); getChildren().add(webView); } } private Scene scene; MyBrowser myBrowser; @Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Frontend"); myBrowser = new MyBrowser(); scene = new Scene(myBrowser); primaryStage.setScene(scene); primaryStage.show(); } }

    I suspect this is because they are now using a newer webkit JDK-8156698 but it might have been a bug before (you can take a look at the 8u112 bug fixes list.

提交回复
热议问题