I encountered the same issues trying to get a transparent background and have nothing to help there.1 person found this helpful
To get an accurate readout of the above, look it up in a ChangeListener installed on engine.documentProperty().
Once you know the values you can set the pref height and (if desired) width of the webview.
Continuously monitoring the height and updating the preferences as needed is painful, so this technique works best for something which doesn't need to change in size after the initial rendering (like an html date picker for instance).
You can also use stuff like yui3 reset css (http://yuilibrary.com/yui/docs/cssreset/) to remove margins and paddings from inside the webview to get a tight fit of content if desired.
It would be perhaps better to subclass WebView and override some functions to perform a custom layout (or just get the appropriate functionality implemented in WebView), but WebView is final, so this was the best I could come up with for now.
Thanks a lot. This took me a little bit further although I am feeling like standing on my head.
In case you are interested. You can achieve a kind of transparency effect by playing with the blend modes of the web view. If you have a web page with a white background and black letters, you can achieve a transparency effect by setting the blend mode to MULTIPLY.
As these were great questions and no satisfactory answer has been proposed for either of them, I filed a couple of WebView tweak requests for these features:1 person found this helpful
http://javafx-jira.kenai.com/browse/RT-25004 "Allow for transparent backgrounds in WebView"
http://javafx-jira.kenai.com/browse/RT-25005 "Automatic preferred sizing of WebView"
Just in case this helps,
String heightText = msgField.getEngine().executeScript("window.getComputedStyle(document.body, null).getPropertyValue('height')").toString();
double height = Double.valueOf(heightText.replace("px", ""));
I see http://javafx-jira.kenai.com/browse/RT-25004 "Allow for transparent backgrounds in WebView" has a related prerequisite case https://javafx-jira.kenai.com/browse/RT-29186, which is fixed for Java8.
In it's description is mentioned the following: "Furthermore, for those users who are comfortable using internal APIs, this will immediately make transparent background possible in WebView"
I'm trying to figure out what that internal API would be, but no luck so far. Tried following the links to the commits in the comments to get an idea, but they go nowhere (for me at least).
Anyone has an idea?