private void expandToContentHeight() { try { WebView webView = getWebview(); String heightText = webView.getEngine().executeScript("document.body.offsetHeight").toString(); double height = Double.valueOf(heightText.replace("px", "")); Platform.runLater(new Runnable() { @Override public void run() { System.out.println(height); if (height != 0.0) webView.setPrefHeight(height); } }); } catch (Exception ex) { LOG.error(ex); LOG.debug("Error occurred in method expandToContentHeight"); } }
/** * @param chartParentPane that should contain the {@link WebView} used by this chart controller * @param webEngineConsumer a {@link WebEngine} consumer that knows how to retrieve the content to be displayed, without relying on the value returned by {@link #createChartData()} */ public HtmlChartController(Pane chartParentPane, Consumer<WebEngine> webEngineConsumer) { this.webEngineConsumer = webEngineConsumer; chartParentPane.getChildren().add(webView); chartParentPane.widthProperty().addListener((obs, oldVal, newVal) -> {webView.setPrefWidth(newVal.doubleValue());}); chartParentPane.heightProperty().addListener((obs, oldVal, newVal) -> {webView.setPrefHeight(newVal.doubleValue());}); }
double height = new Double(i); height = height + 20; rssWebView.setPrefHeight(height); rssWebView.getPrefHeight();