我尝试在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浏览器中访问http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm
并成功加载,我的代码有什么错误?
答案 0 :(得分:0)
您安装了哪个版本的JDK。我在Windows 8.1上使用IDK 8u77并在Eclipse Mars2上运行你的代码,它运行得很好。试试latest version from here.检查一下是否有效。