Remove ScrollBar in Javafx WebView

How to automatically remove scrollbar in Javafx WebView?

When you click "Cadastre", a screen will open, this screen is in javascript and not configured due to the scroll bar, so we wanted to delete it.

enter image description here

+5
source share
1 answer

Usually for ScrollPaneyou do something like this:

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

However, the scrollbars inside the WebView are not your JavaFX UI control, but part of the displayed web page. So you control it with CSS:

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

You can save this as .css and apply it as a user style sheet, similar to the user style sheet in regular browsers using this code:

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

, :

webView.getEngine().setUserStyleSheetLocation(getClass().getResource("/path/to/style.css").toExternalForm());
+15

All Articles