Solved

Turn off cursor

Posted on 2013-12-19
4
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hive vs Impla in Hadoop 1 78
How to overcome error: The method of type x must override y or implement a supertype method 4 24
Java array 21 85
"lblTime is not declared" 3 34
In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

733 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