Hello,
I saw that in LWJGL there’s a method like Mouse.grab() which will hide the system cursor, so you can use your own. How can I do this in standard Java?
Hello,
I saw that in LWJGL there’s a method like Mouse.grab() which will hide the system cursor, so you can use your own. How can I do this in standard Java?
this is what I do for the fullscreen version of Goomba4K:
setCursor(getToolkit().createCustomCursor(new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR),new Point(0,0),""));
this just sets the cursor as transparent, but you can use your own custom image if you want.
So I just use a 1px transparent image for the cursor, and draw the real (animated) cursor by myself?
So far I can’t seem to be able to load animated GIFs as cursors, so I’ll just implement that myself…
Why not just change the cursor to the current frame of animation every time the cursor’s animation moves to the next frame? That should produce better code that having a 1 pixel cursor and then drawing your own cursor on top of it.
You could also consider setting the cursor to null instead of using a 1 pixel cursor, but that might stop the Component from receiving mouse events. (I’m not sure.)
As the javadoc describes, “if this parameter is null then this component will inherit the cursor of its parent”
If it is a top-level Component, I believe it uses the system cursor.
Animating the cursor via repeated setCursor calls may not work well on all systems - though I must confess I havn’t tried it.
You could make the cursor invisible and draw your own animated cursor manually by drawing a BufferedImage at the cursor position.
-JAW