java - 如何在javaFX中创建自定义光标?

标签 java javafx windows-8.1

我正在尝试在 javaFX 中创建自定义光标。这是我的代码:

Image image = new Image("mycursor.png");

Pane pane= new Pane();
pane.setCursor(new ImageCursor(image,
                                image.getWidth() / 2,
                                image.getHeight() /2));

Windows 8.1 的光标创建不起作用吗?

最佳答案

查看ImageCursor.getBestSize()方法和ImageCursor.getMaximumColors()并查看它们返回的内容,然后尝试匹配最佳尺寸和最大颜色的自定义光标图像。这很可能是 Windows 8.1 的 32x32 光标。

这里引用了 ImageCursor.getBestSize() javadoc:

Gets the supported cursor size that is closest to the specified preferred size. A value of (0,0) is returned if the platform does not support custom cursors.

Note: if an image is used whose dimensions don't match a supported size (as returned by this method), the implementation will resize the image to a supported size. This may result in a loss of quality.

Note: These values can vary between operating systems, graphics cards and screen resolution, but at the time of this writing, a sample Windows Vista machine returned 32x32 for all requested sizes, while sample Mac and Linux machines returned the requested size up to a maximum of 64x64. Applications should provide a 32x32 cursor, which will work well on all platforms, and may optionally wish to provide a 64x64 cursor for those platforms on which it is supported.

还要确保您创建的 Pane 大小不为零,并且该 Pane 已添加到场景中,以便实际上有一个 Pane 区域可供鼠标悬停并查看光标变化。

关于java - 如何在javaFX中创建自定义光标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21894882/

相关文章:

java - Java 集的并集或交集

java - 如何将 JavaFx TreeView 与 POJO 结合使用

java - 从 JFrame 中的 JFXPanel 打开 JavaFX 子对话框

JavaFX 同时多个 Controller

powershell - 我可以从 Windows 8.1 中删除 Windows 应用商店吗?

javascript - Sockets.io 接收但不发送消息

java - Android:找不到这样的文件或目录错误?

java - NoClassDefFound错误: Logcat reads $1 indicating error on inner class but I have none

dll - 依赖walker挂起

c# - 在 Windows Server 2012 上将 IIS 连接到 SQL Server 2014