Transclucency for windows : Make a full window translucent with a specified alpha level

Per pixel translucency : Make a part of the window translucent.

Shaped windows : You can now create windows with a certain shape, like circle, ovale, triangle, …

We’ll see all this features in that post. All the examples are tested in Windows Seven 64 bits, because the transclucency isn’t supported in Ubuntu 10.04 at the time I write the article.

First of all, you can now set the opacity of the window with the setOpacity(float opacity) of the Window class. With that, the entire window is made translucent. There is some limitations with that new method. An opacity less than 1.0 isn’t supported if the window use full-screen mode or if the simple translucency isn’t supported. You can test if the window transclucency is supported with the isWindowTranslucencySupported() method added to the GraphicsDevice class :

So, it’s really simple to make a window translucent. But there is more you can do. You can also make only a set of pixel translucent using their background color. Like the translucent window, there is some limitations, the window must not be in full-screen and the system must support the per pixel translucency. You can test it the same way as the first time :

The example is very simple of course, but you can imagine doing a lot of things using that feature.

And now a crazy new feature : shaped windows !

Java 7 allows you to create Window of whatever shape you want. You can create circle, triangle, elliptic windows or more complex shape, a smiley by example. To do that, you have now access to the setShape(Shape shape) method in the Window class. Like the other two, full screen mode is not allowed and the per pixel transparency must be supported by your computer :

And of course you can combine translucency and shaped windows adding setOpacity(0.5f) to your frame. For that the Per Pixel Translucency and the Per Pixel Transparency must be supported. That give us this kind of window :

Java 7 : Translucent Shaped Window

Here we are. We’ve now covered the new translucency features of Java 7. I think it’s really interesting and make Java Desktop Applications more competitive. But I think there is still work to do in Swing before doing that kind of fun stuff.