【问题标题】:Cant load WebView in JavaFX 2.0 and 8.0无法在 JavaFX 2.0 和 8.0 中加载 WebView
【发布时间】:2016-07-26 14:07:12
【问题描述】:

我尝试在我的 Netbeans 7.2 (Java 1.7.u79) 和 Netbeans 8.0.2 (Java 1.8 u45) 中运行以下代码,但它不工作!

package com.main;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

    public class RBrowser extends Application {

        @Override
        public void start(Stage primaryStage) {
            WebView browser = new WebView();
            final WebEngine webEngine = browser.getEngine();
            webEngine.load("http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm");

            Button b = new Button("Show Console");
            b.setOnAction(new EventHandler<ActionEvent>(){
                @Override
                public void handle(ActionEvent t) {
                    webEngine.executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');}");
                }
            });

            VBox root = new VBox();
            root.setAlignment(Pos.CENTER);
            root.getChildren().addAll(browser,b);

            Scene scene = new Scene(root, 700, 550);

            primaryStage.setTitle("Google Map");
            primaryStage.setScene(scene);
            primaryStage.show();
        }

        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            launch(args);
        }

    }

我尝试在 Google Chrome 浏览器中访问 @987654321@ 并成功加载,我的代码有什么问题?

【问题讨论】:

  • 您能否详细说明您收到的回复?是否有错误,或者我们可以看到一些输出?
  • 顺便说一句,它在 NetBeans 8.1 中对我有用
  • 这里的代码也很完美。在 Mac OSX Capitan 上使用 Java 1.8.0_74 在 Eclipse Mars2 上运行。任何控制台错误/输出?
  • 控制台没有报错,但是我的PC上安装了很多JDK,这些会影响WebView的行为吗?

标签: java javafx javafx-2 javafx-8


【解决方案1】:

您安装了哪个版本的 JDK。我在 Windows 8.1 上使用 IDK 8u77 并在 Eclipse Mars2 上运行您的代码,它运行良好。试试latest version from here. 检查它是否有效。

【讨论】:

    猜你喜欢
    • 2017-03-17
    • 1970-01-01
    • 2015-08-27
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    • 1970-01-01
    • 2011-10-14
    相关资源
    最近更新 更多