Remove The ScrollBar in the WebView Javafx [closed

2019-02-07 07:36发布

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条回答
戒情不戒烟
2楼-- · 2019-02-07 08:03

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());
查看更多
登录 后发表回答