Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
837 views
in Technique[技术] by (71.8m points)

java - How to create custom cursor in javaFX?

I am trying to create custom cursor in javaFX. Here is my code:

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

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

Is the creation of cursors for windows 8.1 does not work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Checkout the ImageCursor.getBestSize() methods and ImageCursor.getMaximumColors() and see what they return, then try a custom cursor image which matches the best size and maximum colors. Most likely this will be a 32x32 cursor for Windows 8.1.

Here is a quote from the 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.

Also ensure that the pane that you create is not of zero size and that the pane has been added to a scene so that there is actually a pane area to mouse over and see the cursor change.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...