سؤال

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.

هل كانت مفيدة؟

المحلول

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/

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top