您可以使用以下调用获取WebView中显示的文档的高度:
webView.getEngine().executescript( "window.getComputedStyle(document.body, null).getPropertyValue('height')");演示呼叫使用情况的完整应用程序:
import javafx.application.Application;import javafx.beans.value.*;import javafx.scene.Scene;import javafx.scene.web.*;import javafx.stage.Stage;import org.w3c.dom.document;public class WebViewHeight extends Application { @Override public void start(Stage primaryStage) { final WebView webView = new WebView(); final WebEngine engine = webView.getEngine(); engine.load("http://docs.oracle.com/javafx/2/get_started/animation.htm"); engine.documentProperty().addListener(new ChangeListener<document>() { @Override public void changed(Observablevalue<? extends document> prop, document oldDoc, document newDoc) { String heightText = webView.getEngine().executescript( "window.getComputedStyle(document.body, null).getPropertyValue('height')" ).toString(); double height = Double.valueOf(heightText.replace("px", "")); System.out.println(height); } }); primaryStage.setScene(new Scene(webView)); primaryStage.show(); } public static void main(String[] args) { launch(args); }}上面的答案的来源:Oracle
JavaFX论坛WebView配置线程。
针对基于Java的API的相关功能的相关问题跟踪器请求:
RT-25005 WebView的自动首选大小。



