How to hide scrollbars in the JavaFX WebView


Question

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 is abstract; cannot be instantiated"

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.

Thanks! S

1
3
6/27/2012 12:47:03 AM

I wrote the scroll bar hiding code you refer to and posted it to a forum.

I tried it again using WinXPsp3, JavaFX 2.2b13, JDK7u6b14ea and it still works for me.

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);
        }
      }
    });
  }
}

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.

3
6/27/2012 2:41:48 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon