移除 WebView Javafx 中的 ScrollBar [英] Remove The ScrollBar in the WebView Javafx

查看:38
本文介绍了移除 WebView Javafx 中的 ScrollBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆