JDK-8143597 : Provide public API to access current mouse pointer location
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8u66
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: other
  • CPU: x86
  • Submitted: 2015-11-18
  • Updated: 2018-07-17
  • Resolved: 2018-07-17
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
Up to now, no public API is available to access the current mouse pointer location (when the mouse it not moved). There is a workaround using java.awt.MouseInfo.getPointerLocation(), which does not work for Mac:

PointerInfo pi = MouseInfo.getPointerInfo();
java.awt.Point mp = pi.getLocation();

On Mac there is the following workaround using  com.sun.glass.ui.Robot, which is not public API:

com.sun.glass.ui.Robot robot = com.sun.glass.ui.Application
					.GetApplication().createRobot();
Point mp = new Point(robot.getMouseX(), robot.getMouseY());

There is no direct means to obtain the current pointer location through JavaFX public API.

JUSTIFICATION :
There is no direct means to retrieve the current mouse pointer location via public API of JavaFX. The workaround for Mac relies on accessing JDK internal API, so that this workaround will no longer work with Jigsaw:

 -> com.sun.glass.ui.Application                       JDK internal API (javafx.graphics)
      -> com.sun.glass.ui.Robot                             JDK internal API (javafx.graphics)



Comments
This is now available as part of the FX Robot API. Closing as a duplicate of JDK-8090763.
17-07-2018

It seems the AWT problem on the Mac was related to JavaFX 2.2. I performed some tests using Java 1.8.0_91 on MacOSX 10.11.6, where PointerInfo pi = MouseInfo.getPointerInfo(); java.awt.Point mp = pi.getLocation(); now seems to work as expected, so the workaround for Mac no longer has to rely on JDK internal API (and will thus still work in a JIGSAW environment).
13-09-2016