Calan54
Calan54

Reputation: 357

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.

Upvotes: 0

Views: 1671

Answers (2)

Hirak
Hirak

Reputation: 3649

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/

Upvotes: 2

MadProgrammer
MadProgrammer

Reputation: 347184

To create a custom cursor you would need to use Toolkit#createCustomCursor(Image, Point, String), this will return a Cursor which you can apply to components

This will require you to a image, preferably with transparency support, define the "hot spot" which is used to determine where the MouseEvent is generated, and a name for the cursor

Upvotes: 1

Related Questions