I was wondering if there is a way to extract an Image object from a Cursor object in Java.
A use for this would be for instance :
Image img = extractCursorImage(Cursor.getDefaultCursor());
Which you then can draw on a toolbar button (that’s the purpose I want it for).
The Cursor class is pretty abstract – all the important stuff is delegated to native code, so you can’t just draw one onto at graphics context. There isn’t an immediately obvious way of getting round the need to either predefine the icons or do it in native code.
Below is some code to draw built-in Windows cursors using the JNA library. If you can use JNA, you can avoid C++ compilers.
I’m probably making too many native calls, but the cost is not significant for one-shot icon generation.
hand cursor drawn in Java http://f.imagehost.org/0709/hand.png
Code to display a cursor as a Java image:
User32.dll interface:
Gdi32.dll interface: