Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top