Solved

Turn off cursor

Posted on 2013-12-19
4
253 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now