Hi,
I am using the mouse to control the camera, is it possible to remove the mouse pointer when it’s over the JFrame? I mean, I don’t want to see it, I might put a target at the center of the screen or something else in the future.
Hi,
I am using the mouse to control the camera, is it possible to remove the mouse pointer when it’s over the JFrame? I mean, I don’t want to see it, I might put a target at the center of the screen or something else in the future.
You can get an invisible cursor with this code:
Dimension d = Toolkit.getDefaultToolkit().getBestCursorSize( 1, 1 );
Image invisibleImage = new BufferedImage( d.width, d.height, BufferedImage.TYPE_INT_ARGB );
Cursor invisibleCursor = Toolkit.getDefaultToolkit().createCustomCursor( invisibleImage, new Point(), "Invisible cursor" );
and then use the setCursor( invisibleCursor ) on your JFrame.
Note that the pointer will still be able to leave the JFrame, look at java.awt.Robot to fix this if needed.
I’ve been looking into using java.awt.Robot to do as you say (e.g. to keep it from leaving the frame). But the javadocs suggest that it isn’t supposed to be used in applications (e.g. for “testing”). Is there some reason that they say it should be only used for testing?
Hi,
The first reason I saw not to use this method is related to the fact that it’s not a good practice in general to move the cursour position when an user/operator is also moving it.
That’s a general ergonomic principle.
But if you want to force the mouse to stick to a frame and if it don’t bother your users, you can use this method I think.