如何在 JavaFX WebView 中隐藏滚动条 [英] How to hide scrollbars in the JavaFX WebView
问题描述
我正在尝试删除 javafx webview 中的滚动条.搜索论坛,建议如下:
I'm trying to remove the scrollbars in a javafx webview. Search on forums, the suggestion is to make them invisible as follows:
browser.getChildrenUnmodifiable().addListener(new ListChangeListener<Node>() {
@Override public void onChanged(Change<? extends Node> change) {
Set<Node> deadSeaScrolls = browser.lookupAll(".scroll-bar");
for (Node scroll : deadSeaScrolls) {
scroll.setVisible(false);
}
}
})
但是,我收到以下错误:
However, I receive the following error:
"trait ListChangeListener 是抽象的;不能被实例化"
"trait ListChangeListener is abstract; cannot be instantiated"
我可以理解为什么它失败了,但话说回来,为什么人们成功地使用此代码?我使用的是 Eclipse,代码被 Scala 代码包围.
I can understand why its failing, but then again, why are people using this code with success? I'm using Eclipse and the code is surrounded in Scala code.
谢谢!
推荐答案
我写了你参考的滚动条隐藏代码和将其发布到论坛.
I wrote the scroll bar hiding code you refer to and posted it to a forum.
我使用 WinXPsp3、JavaFX 2.2b13、JDK7u6b14ea 再次尝试了它,但它仍然适用于我.
I tried it again using WinXPsp3, JavaFX 2.2b13, JDK7u6b14ea and it still works for me.
我从未尝试从 Scala 访问代码,因此您可能遇到了一些 Java<->Scala 互操作性问题.Java 没有特征,因此您收到的错误将与 Scala 相关.我在您的问题中添加了 Scala 标签,所以也许具有 Scala 专业知识的人可以提供帮助.
I have never tried accessing the code from Scala, so you may have run into some Java<->Scala interoperability issue. Java does not have traits, so the error you receive would appear Scala related. I added a Scala tag to your question, so maybe somebody with Scala expertise could help.
这是一个简短的、可编译的测试应用程序,我用来重新检查功能.
Here is a short, compilable test application I used to recheck the functionality.
import java.util.Set;
import javafx.application.Application;
import javafx.collections.ListChangeListener;
import javafx.collections.ListChangeListener.Change;
import javafx.scene.*;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
// demos showing a webview which does not visibly display scrollbars.
public class NoScrollWebView extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(Stage primaryStage) {
// show a doc in webview.
final WebView webView = new WebView();
webView.getEngine().load("http://docs.oracle.com/javafx/2/get_started/jfxpub-get_started.htm");
primaryStage.setScene(new Scene(webView));
primaryStage.show();
// hide webview scrollbars whenever they appear.
webView.getChildrenUnmodifiable().addListener(new ListChangeListener<Node>() {
@Override public void onChanged(Change<? extends Node> change) {
Set<Node> deadSeaScrolls = webView.lookupAll(".scroll-bar");
for (Node scroll : deadSeaScrolls) {
scroll.setVisible(false);
}
}
});
}
}
这里最好的解决方案可能是提供一个新的 WebView 控件外观,其中没有任何控件 - 但在 WebView 控件开源之前这可能会很困难.
The best solution here, would probably be to provide a new WebView control skin which does not not have any controls in it - but that would likely be difficult until the WebView control is open sourced.
这篇关于如何在 JavaFX WebView 中隐藏滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!