Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

scala - How to hide scrollbars in the 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 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...