• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Turn off cursor

I have a java applications and I need to be able to disable and enable the cursor.  Any suggestions?
0
sargent240
Asked:
sargent240
  • 2
  • 2
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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!
0
 
sargent240Author Commented:
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.
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Sorry, just went back through older questions that I had participated in and I found this one that I lost somehow! Sorry about that. Probably dropped off my first page of emails over the xmas/new year break! :)


Ok, so I understand now what you want to do. One thing that I was wondering, although I'm guessing that you have already tried this, does the "box" that is on the screen respond with a MouseClick event (in addition to the MouseMotion event that you are currently using) when "touched" by the operator. If you have tried that, or something like that, could you let us know what happened, or what didn't happen, because I would be surprised if that couldn't be made to work?

The problem is that due to Java being a cross-platform type of language, there is generally a lot of hardware and even OS abstraction in place, so I don't think you will be able to find a solution to disable/enable a particular piece of hardware in that way from your application, ie. in Windows what would need to be done is entirely different to what you would do in Linux or Mac, etc.

The only other thing that I can think of is that there appears to be some Java "touch" specific libraries out there, that I guess use native code to access the devices directly. I've never used anything like that so I can't comment to much but from a quick search it looks like there are a few libraries out there, but that there doesn't seem to be any that are really well tested and used, etc. So you might find something that works for just what you want or they might all be a waste of time! :)  Sorry I can't help further along those lines.
0
 
sargent240Author Commented:
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now