JavaFX webview,获取文档高度 [英] JavaFX webview, get document height
本文介绍了JavaFX webview,获取文档高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在JavaFx中获取webview控件的文档高度?
解决方案
您可以获取文档的高度使用以下调用显示在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;
$ b $ 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 ();
double height = heightText = 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的相关功能的跟踪器请求:
< a href =https://javafx-jira.kenai.com/browse/RT-25005 =noreferrer> RT-25005自动优先选择WebView大小。
How can I get the document height for a webview control in JavaFx?
解决方案
You can get the height of a document displayed in a WebView using the following call:
webView.getEngine().executeScript(
"window.getComputedStyle(document.body, null).getPropertyValue('height')"
);
A complete app to demonstrate the call usage:
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); }
}
Source of the above answer: Oracle JavaFX forums WebView configuration thread.
Related issue tracker request for a Java based API for a related feature:
RT-25005 Automatic preferred sizing of WebView.
这篇关于JavaFX webview,获取文档高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文