Solved

Turn off cursor

Posted on 2013-12-19
4
268 Views
Last Modified: 2014-01-06
I have a java applications and I need to be able to disable and enable the cursor.  Any suggestions?
0
Comment
Question by:sargent240
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:mccarl
ID: 39731061
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
 

Author Comment

by:sargent240
ID: 39734066
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
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39758466
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
 

Author Closing Comment

by:sargent240
ID: 39760919
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 50
JAVA API design with micro service cloud in mind 1 47
hashmap order 17 37
What browser will run Java? 7 65
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This is an explanation of a simple data model to help parse a JSON feed
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question