I want to add padding to a WebView
in JavaFX, like you can add padding to a label.
I have already found this stack overflow discussion about WebView
on Android, and it has bugs with the padding. However, I want to add a WebView
in a BorderPane
on a desktop application with padding on all sides.
I tried to use setPadding()
however, this method doesn`t exist.
Is there an alternative for it?
CodePudding user response:
As shown here, you can use the BorderPane
Optional Layout Constraints to add "Margin space around the outside of the child."
WebView webView = new WebView();
BorderPane.setMargin(webView, new Insets(16));
top.setCenter(webView);
CodePudding user response:
You can, add a margin bottom to the label, to replace the idea of padding it, or you can use JS when load the WebView and padding inside the html. Like this:
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
webView.loadUrl("javascript:document.body.style.padding=\"10%\";void 0");
}
});