JavaFX WebView: custom cursors not working?

南笙酒味 提交于 2021-01-29 12:12:00

问题


I tried to get css custom cursors to work with Java WebView within a tag, to no avail.

For example:

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) {
        primaryStage.setTitle("JavaFX WebView Example");

        WebView webView = new WebView();
        String cursorUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/8/8c/Pixel_51_icon_cursor_click_top_right.svg/36px-Pixel_51_icon_cursor_click_top_right.svg.png";
        String content = String.format("<body style=cursor: url('%s'), auto;>", cursorUrl);
        content = content + "<br>some text<br> a link: http://google.com </body>";
        System.out.println(content);
        webView.getEngine().loadContent(content);

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

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

which just shows the regular cursor.

I also tried to replace the .png cursor by a .cur file, as well as remove the quotes around the url. Nothing seems to work.

Does WebView not support the feature? Other cursor such as wait and grab work fine.


回答1:


It was a mere problem related to quotes.

I changed the content line to

String content = String.format("<body style=\"cursor: url('%s') 10 10, auto\";>", cursorUrl);

and it worked fine.



来源:https://stackoverflow.com/questions/61038768/javafx-webview-custom-cursors-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!