Remove The ScrollBar in the WebView Javafx [closed

2019-02-07 07:13发布

问题:

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.

回答1:

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());