WebView无法正确显示

时间:2016-04-13 02:32:14

标签: java javafx javafx-2 javafx-webengine

Webview is not displaying correctly

leftside是 Google Chrome 中加载的 html页面,右侧是 JavaFx WebView中加载的 html页面 ,问题是Google Map的导航面板没有显示在 JavaFx WebView 中。我正在使用 Java 7u79

GoogleMap.java

webView = new WebView();
webEngine = webView.getEngine();
webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>(){
    @Override
    public void changed(ObservableValue<? extends State> ov, State t, State t1) {
        System.out.println("STATE : " +  t1);
        if(t1.equals(State.SUCCEEDED)){
            root.getChildren().remove(indicator);
        }
    }
});

indicator = new ProgressIndicator();
indicator.setMaxSize(40, 40);

String htmlcode = getFileContent("GoogleMap.html");
webEngine.loadContent(htmlcode);

root = new StackPane();
root.setAlignment(Pos.CENTER);
root.getChildren().add(webView);
root.getChildren().add(indicator);


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

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

GoogleMap.html

<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
  var mapProp = {
    center : new google.maps.LatLng(51.508742,-0.120850),
    zoom : 5,
    mapTypeId : google.maps.MapTypeId.ROADMAP
  };
  var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style>
    body
    {
        padding : 0; 
        margin  : 0;
    }
    #googleMap
    {
        width  : 550px;
        height : 400px;
    }
</style>
</head>

<body>
<div id="googleMap"></div>
</body>

</html>

1 个答案:

答案 0 :(得分:0)

我一切都好。 enter image description here

java 1.8.0_73也许您应该尝试更新Java或获取更新的JavaFX?