Soft clipping and per-pixel translucency for Swing windows
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).
Related posts:
- More tricks with translucent Swing windows The java.net site has just published my article on translucent and shaped windows, and it...
- Translucent and shaped windows in core Java I first spotted it about a month ago, and today’s build 12 of JDK 6.0u10...
- Translucent and shaped windows in JDK 7 The latest weekly drop of JDK 7 (b57) has finally exposed the functionality of translucent...
- Using multiple skins for different Swing windows A considerable part of the new skinning layer of Substance is geared towards enabling writing...
March 4th, 2008 at 10:54 pm
Hi Kirill,
I went to a Sun Tech Days thing in Sydney yesterday and the speaker showed a screenshot of the picture in your blog of a clipped-frame! So yeah, word travels fast. In fact, the speaker (who was discussing the consumer JRE and java 7) actually seemed like he didn’t know about the window-clipping until he saw your blog.
Thanks for putting this news up.
Best regards,
Keith
April 16th, 2008 at 7:49 am
why now the jdk 7.0 does not content the AWTUtilities?
and which version contents this now?
my email:forever_ami@163.com
thank you !
April 16th, 2008 at 7:52 am
Ami – that would be a question better asked on the Swing & AWT forum.