The entry on translucent and shaped windows in Swing has generated quite a lot of discussion and interest. It appears that readers were interested in per-pixel translucency and soft clipping for shaped windows, and Anthony has provided a few tips on how to achieve this. So, pending an official guide / tutorial from the AWT team (hint hint), here is my take.
What you see here is a JWindow with soft-clipped top-left and top-right corner and pixel-level translucency in the bottom half. In addition to Anthony’s instructions, i have used the following:
- Chris Campbell‘s tutorial on soft clipping. This takes care of the top-left and top-right corners of the window
- Romain Guy‘s tutorial on reflection and improvement by Sebastien Petrucci (see comment section)
- Sample image from Petursey’s Flickr stream (licensed under Creative Commons).
The source code is here. I’m pretty sure that it’s not the best (and not the most readable), but it shows the potential. You’re more than welcome to use this code as a starting point (don’t forget to credit Chris, Romain and Sebastien if you’re reusing it).