This is certainly not possible in cross platform Java, and to be honest isn't really possible in a reliable sense even if we resort to native code.
The (non-reliable) way to do this natively for Windows would be to use GetDevicePowerState
- find it in kernel32.dll
. However, from experiments I did using this function a while back I can say it definitely doesn't work with every monitor, and obviously even if this was reliable it would be a Windows-only solution.
If you do want to go down this route bearing in mind the above limitations, then use MonitorFromPoint
to grab the handle to the primary monitor (pass in a 0,0 as the point and use the MONITOR_DEFAULTTOPRIMARY
flag.)