Archived

This topic is now archived and is closed to further replies.

[java] [Java] Custom Cursors

This topic is 6016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've managed to change the cursor in my programs to a predefined cursor but i was wondering if anyone knew how to create your own cursor and change to that. also when i compile my program i get deprecation stuff. This is because it's going to the Frame's setCursor instead of Components setCursor... anyone know how i can specify the second one? Thanks alot Ford! theres an infinate amount of monkeys outside wanting to talk to you about a script of Hamlet they created!
www.mikeditum.co.uk
Edited by - mcd9 on June 26, 2001 8:59:12 AM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
no idea, but I bet you''ll get more answers if you post in the java forum (it is near the bottom)

Share this post


Link to post
Share on other sites
Use Toolkit.createCustomCursor

e.g.

Toolkit tk = Toolkit.getDefaultToolkit();
Cursor cursor = tk.createCustomCursor( myImage, new Point( 0, 0 ), "my cursor" );

setCursor( cursor );


That''ll give you a cursor with a "hot spot" at 0, 0 (ie the top left corner is the bit that clicks).
You might have some trouble if the underlying OS won''t cooperate. Also this only works under 1.2 or higher (so it won''t work in an applet).

John

Share this post


Link to post
Share on other sites
I suppose you could always create a cursor thats like 1 pixel x 1 pixel... though that still wouldn''t be completely invisible.
I''m assuming setCursor(null) wouldn''t work... either throw exception or just set it to default.
apart from that i don''t know.. I assume you must be able to have transparent images as there are sections in cusors that are transparent... dunno how though!

Share this post


Link to post
Share on other sites
Either use a transparent 1x1 gif for your cursor image, or create an internal image using a MemoryImageSource that has no alpha component:

int[] pixels = { 0x00000000 };
MemoryImageSource source = new MemoryImageSource( 1, 1, pixels, 0, 1 );
Image image = createImage( source );

Share this post


Link to post
Share on other sites
From the J2SE1.3.1 documentation of Toolkit.createCustomCursor()
quote:

If the image to display is invalid, the cursor will be hidden (made completely transparent), and the hotspot will be set to (0, 0).



I assume that means you could just call createCustomCursor(null, new Point(0, 0), "invisible") to get an invisible cursor.

Share this post


Link to post
Share on other sites