[java] [Java] Custom Cursors

Started by
6 comments, last by mcd9 22 years, 9 months ago
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
Ford! theres an infinate amount of monkeys outside wanting to talk to you about a script of Hamlet they created!www.mikeditum.co.uk
Advertisement
no idea, but I bet you''ll get more answers if you post in the java forum (it is near the bottom)
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
Thanks that great! I''ll go have a play with that!

Ford! theres an infinate amount of monkeys outside wanting to talk to you about a script of Hamlet they created!

www.mikeditum.co.uk
Ford! theres an infinate amount of monkeys outside wanting to talk to you about a script of Hamlet they created!www.mikeditum.co.uk
Can you hide the cursor? Or make it invisible?

-cdb
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!
Ford! theres an infinate amount of monkeys outside wanting to talk to you about a script of Hamlet they created!www.mikeditum.co.uk
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 );
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.

This topic is closed to new replies.

Advertisement