WebView无法在JavaFX 2.0

时间:2016-03-15 06:24:53

标签: java javafx javafx-2 javafx-8

当我双击html file时,会预览地图,但当我在WebView中加载时,不会显示任何内容。

以下是代码:

StringBuilder sb = new StringBuilder();

InputStream in = getClass().getResourceAsStream("map.html");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while((line = reader.readLine()) != null){
    sb.append(line);
}
reader.close();

WebView browser = new WebView();
browser.setPrefSize(700, 550);
webEngine = browser.getEngine();
webEngine.loadContent(sb.toString());
webEngine.setOnAlert(new EventHandler<WebEvent<String>>(){
    @Override
    public void handle(WebEvent<String> event) {
        System.out.println("Alert Message > " + event.getData());
    }
});

这是名为 map.html 的html文件:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    </style>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
    </script>
    <script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(-34.397, 150.644),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);
      }
    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:400px; height:300px"></div>
  </body>
</html>

您认为这个问题是什么?请注意:webview的工作加载器的状态为SUCCEEDED,表示没有错误。

0 个答案:

没有答案