Link to home
Start Free TrialLog in
Avatar of sargent240
sargent240Flag for United States of America

asked on

Turn off cursor

I have a java applications and I need to be able to disable and enable the cursor.  Any suggestions?
Avatar of mccarl
mccarl
Flag of Australia image

Are you talking about a Java Swing application? And by "disable and enable the cursor" do you basically mean hiding the cursor and then showing it again?

If so, you can create a "blank" cursor (as Java/Swing doesn't provide one by default) with the following line of code...
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB), new Point(0, 0), "blank");

Open in new window

Then whenever you want to hide the cursor, you can do this...
jframe.setCursor(blankCursor);

Open in new window

And to show it again, you can do this...
jframe.setCursor(Cursor.getDefaultCursor());

Open in new window

Assuming the "jframe" is a reference to your main JFrame that your application runs in. If you only want to hide the cursor in a specific part of your UI, you can just set the blankCursor on that specific UI element.

Oh, and by the way, you might have guessed from the above that since the cursor is only "hidden" then you can theoretically still click on UI items, or drag, etc. you just can't see exactly where it is!
Avatar of sargent240

ASKER

Boy, I did not handle this question very well.  Really I would like to be able to disable  and enable the mouse.  I have an applications using a touch screen and I am using a mouse motion event to detect a touch on a box on the touch screen.  When the user touches the button I increment or decrement a number.  It works great except if the operator moves the mouse across the button the number goes up by a bunch rather that one.  My though is if I disable the mouse I would not have the problem and then enable it again when the operator leaves the program.
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.  I have resigned myself to using the mouse and not the touch screen in this application or I would have been putting the heat on ya.  Thank you for the info
Cheers