【问题标题】:JavaFX WebView: custom cursors not working?JavaFX WebView:自定义光标不起作用?
【发布时间】:2020-04-05 06:19:10
【问题描述】:

我试图让 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 等其他光标工作正常。

【问题讨论】:

  • 用户代理可能不支持该功能。您可以打印用户代理并在网络上搜索该特定代理和版本的功能。
  • 用户代理是Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/605.1 (KHTML, like Gecko) JavaFX/10 Safari/605.1

标签: java javafx webview


【解决方案1】:

这只是与引号有关的问题。

我将内容行改为

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

效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 2015-09-01
    • 2012-08-23
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多