Skip to main content

I Will Follow You Into The Dark

Posted by editor on February 28, 2008 at 7:42 AM PST

AWT and Swing windows get opacity options other than 1.0 and 0.0

Befitting the title, Josh Marinacci had a very hacky approach to providing transparent/shaped windows in our book Swing Hacks. Basically, what he did was to use the AWT Robot class to snap a picture of the screen right before showing the window, calculate the portion of the screen overlaid by the soon-to-appear window, and then use those pixels as the background of the window, for the parts that were to appear transparent. This served to make parts of the window transparent, which can also be used to provide shaped windows (in which case the transparent pixels are just around the corners and edges of the window, which itself is still rectangular).

As you might imagine, this was more a cute trick than a practical approach. We did say it was a "hacks" book after all.

But now, we're getting the real deal, as reported in a blog by Kirill