删除WebView Javafx中的ScrollBar [英] Remove The ScrollBar in the WebView Javafx
问题描述
如何在Javafx的WebView中自动删除滚动条?
How to remove the scrollbar automatically in the WebView of Javafx ?
当您单击Cadastre将打开一个屏幕时,此屏幕处于javascript状态且未配置,因为滚动条,所以我们想删除它。
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.
推荐答案
通常用于 ScrollPane
你会做这样的事情:
Normally for a ScrollPane
you would do something like this:
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.NEVER);
但是,WebView中的滚动条不是您的JavaFX UI控件,而是显示的网页的一部分。因此,您可以使用CSS控制它们:
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;
}
您可以将其保存为.css并将其应用为用户样式表,类似地普通浏览器中的用户样式表,使用以下代码:
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());
这篇关于删除WebView Javafx中的ScrollBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!