如何隐藏JavaFX WebView中的滚动条 [英] How to hide scrollbars in the JavaFX WebView

查看:1263
本文介绍了如何隐藏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.

谢谢!
S

Thanks! S

推荐答案

我写了你引用的滚动条隐藏代码和将其发布到论坛

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屋!

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