Remove The ScrollBar in the WebView Javafx


Question

How to remove the scrollbar automatically in the WebView of Javafx ?

When you click "Cadastre" will open a screen, this screen is in javascript and is unconfigured because of the scrollbar, so we wanted to remove it.

enter image description here

1
5
3/19/2013 12:51:39 PM

Accepted Answer

Normally for a ScrollPane you would do something like this:

scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.NEVER);

However, the scrollbars inside WebView are not your JavaFX UI control, but a part of the displayed webpage. Thus, you control them with CSS:

body {
    overflow-x: hidden;
    overflow-y: hidden;
}

You can save this as a .css and apply it as a user stylesheet, similarly user style sheets in normal browsers, using this code:

webView.getEngine().setUserStyleSheetLocation("path/to/style.css");

If the user stylesheet you created is a part of your project's resources then you should externalize it so:

webView.getEngine().setUserStyleSheetLocation(getClass().getResource("/path/to/style.css").toExternalForm());
16
3/19/2013 11:49:48 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon