Java - receive mouse events outside a component

I have the same problem as the person here , that I need to track the location of the frame while dragging it on OS X. The question was not resolved there, therefore:

how can I tell the frame that the mouse event happened in its (OS-native) title bar or, more generally, that the mouse down event happened somewhere on the screen?

+4
source share
2 answers

Since java 1.5

import java.awt.MouseInfo; public class Mouse { public static void main(String[] args) { while ( true ) { System.out.println( MouseInfo.getPointerInfo().getLocation() ); } } } 

EDIT:

Keyboard Root Mouse Hook

http://www.jotschi.de/?p=90

+2
source

Using pure Java, you can never say that an event with a mouse occurred in its (OS-native) title bar, or in this case any event outside your application window (except for headers).

It is important to understand that as a programmer in AWT / Swing, your context and area and power lie only in the application window. The best shot is to use JNI.

0
source

All Articles