Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java fx: How to remove scrollbar from web view?

I want to remove scroll bar from web view since i'm using web based scroll bar

like image 274
Vinod CG Avatar asked Mar 13 '26 23:03

Vinod CG


1 Answers

WebView manages scrolling automatically, so there is no need to put it into a ScrollPane, therefore, You only need to do is control the CSS property overflow or the Webkit-Specify property -webkit-scrollbar (WebView based on Webkit engine).

If you are load page from internet and not from disk, you can't control the CSS yourself, You can inject the css style as following code snippet.

final WebEngine engine = webView.getEngine();
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
    @Override
    public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
        if (newValue == State.SUCCEEDED) {
            String scriptCode = "customize javascript to inject style";
            engine.executeScript(scriptCode);
        }
    }
});
like image 54
Gasol Avatar answered Mar 17 '26 04:03

Gasol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!