Search code examples
javacursor

How would I set a custom cursor in Java?


Recently I have noticed this in Java:

Cursor.CUSTOM_CURSOR

I tried:

setCursor(Cursor.CUSTOM_CURSOR);

And I get the error (probably because the custom cursor hasn't been defined):

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal cursor type

Could anyone tell me how I would set the cursor to a custom one, and how to define the custom cursor.


Solution

  • You will need to create the cursor first before setting

    Cursor customCursor = toolkit.createCustomCursor(cursorImage, cursorHotSpot, "Cursor");

    I found the following tutorial, see if that helps: http://forum.codecall.net/topic/39126-custom-cursors-using-java/