Guillaume F.
Guillaume F.

Reputation: 1130

JavaFX Webview: scrollbar is overlapping content

When using JavaFX Webview, the scrolling bars overlap the content, potentially hiding controls and the likes.

I tested in JavaFX 11, 13, 14, and 15 early access, and all have the same issue.

How do I make it so the scrollbars don't block content?

Here is a short tidbit:

package com.company;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class Main extends Application {
    public static void main(String[] args) { launch(args); }

    public void start(Stage primaryStage) {
        WebView webView = new WebView();
        webView.getEngine().load("https://mdbootstrap.com/docs/jquery/modals/basic/");

        VBox vBox = new VBox(webView);
        Scene scene = new Scene(vBox, 960, 600);

        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

Webview: enter image description hereChrome: enter image description hereFirefox: enter image description hereEdge: enter image description here

Upvotes: 2

Views: 791

Answers (1)

Doombringer
Doombringer

Reputation: 664

I recommend getting ScenicView - it's a great tool. It's helped me a lot with similar issues.

The ScrollBar is part of the WebView. In order to change its behavior, you need to create a custom .css just for the WebView engine.

Then apply said style using:

webView.getEngine().setUserStyleSheetLocation(getClass().getResource("/path/to/style.css").toExternalForm());.

hotzst, mentions in this question a link to this and overall explains that the behavior of the ScrollBar is dependent on the web page. You can alter it by introducing it's own style (via a local .css file) - but it can also damage the structure of the said page.

michael_s, provides some interesting tips and links here that you might want to check out by modifying the webkit used for it.

Unfortunately I'm not that experienced with it, so I don't know what exactly needs to be modified.

Hope this helps a bit at least.

Upvotes: 1

Related Questions