0

I trying to find a method in java which could tell me when the mouse cursor has entered the borders of a folder or file component. Can anybody refer me to a good document or help me on this?

pok
  • 3
  • 1
  • Mouse events happen within the context of the Java application (not your desktop). I don't think this is possible. The best you can do is check if the cursor has left your Java application. – But I'm Not A Wrapper Class Sep 09 '13 at 17:38
  • Thank you Mohammad. So instead of detecting whether cursor has entered a component or not, I have to simply enable the user to click whenever he decides.a bit messy but it seems thats the way to go. – pok Sep 09 '13 at 17:41
  • @pok You can use [PointerInfo](http://docs.oracle.com/javase/7/docs/api/java/awt/PointerInfo.html) to get the pointer coordinates, but you cannot know if it has entered something that isn't part of your java UI. – BackSlash Sep 09 '13 at 17:42

1 Answers1

0

Mouse events happen within the context of the Java application (not your desktop). I don't think this is possible.

The best you can do is check if the cursor has left your Java application. As user BackSlash mentioned,

you can use PointerInfo to get the pointer coordinates, but you cannot know if it has entered something that isn't part of your java application.

http://docs.oracle.com/javase/7/docs/api/java/awt/PointerInfo.html

An alternative option is:

Add an AWTEventListener for focus events. As long as your app has focus before the button is clicked you'll receive a focus lost event. Then query for the pointer position.

The limitation is that, of course, your app loses focus. So depending on what you are ultimately trying to achieve this might not be useful.

Source: https://stackoverflow.com/a/2420208/2498729

Community
  • 1
  • 1