views:

195

answers:

3

i'm having the same issue as the person here, in that i need to track a frame location while it is being dragged on OS X. The question had not been resolved there, so:

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

A: 

Using pure Java, you can never tell that a mouse down event happened on its (OS-native) title bar, or for that case any event outside you application window(excluding title bars).

It's important understand that as a programmer in AWT/Swing your context and realm and power lies only within the application window. Best shot is to use JNI.

Suraj Chandran
+2  A: 

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:

Native keyboard mouse hook

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

stacker
this gives the absolute location of the pointer on screen, but no button events, so it's kind of half the deal...
Jakob
What you are looking for is indeed requiring JNI
stacker
A: 

Excellent solution for mouse co-ordinate information for applications.

Thank You. Regards, nandakihsore

Nandakishore