我正在尝试在 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/