首页 > 解决方案 > JavaFX WebView:自定义光标不起作用?

问题描述

我试图让 css 自定义光标在标签中与 Java WebView 一起使用,但无济于事。

例如:

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

它只显示常规光标。

我还尝试用 .cur 文件替换 .png 光标,并删除 url 周围的引号。似乎没有任何效果。

WebView 不支持该功能吗?其他光标,如waitgrab工作正常。

标签: javajavafxwebview

解决方案


这只是与报价有关的问题。

我将内容行更改为

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

它工作得很好。


推荐阅读