I am trying to develop an application in Java (Swing) that lets me overlay a grid on the screen, and be able to click things behind the grid — say, an icon the desktop for example.
Would I approach this problem with a Transparent JFrame or a Transparent JWindow?
Whatever I use, the transparent window/frame needs to
- always be on top.
- occupy the entire screen.
- register every click with a mouse listener.
- record the coordinates of the clicks on the screen.
- allow me to use the Graphics class to draw a grid on the screen, and other elements, like numbers or images, that should also be click through.
Any direction would be appreciated.
Apologize if I haven’t been specific enough, but I haven’t found a demo window or frame that can do all these things. There’s an example here and another here — but I don’t know how to use WindowUtils in Eclipse. This is my first time in GUI development and I’ve never used external libraries aside from the base Java classes.
If you capture events, you then have to re-introduce them to whatever window is below yours, which is non-trivial. If you don’t capture events, you need to install an OS-specific event handler to capture events of interest.
JNA’s WindowUtils.setWindowTransparent() should provide the paint/event behavior required, or you can use the AWTUtils equivalent provided in more recent JVM releases.