Friday, April 13, 2007

Java Transparent Windows (X11 update)

Update: If your X11 setup supports it (XFCE, metacity + xcompmgr, compiz, etc), the JNA shaped window demo now has window transparency.

Thanks to Romain Guy for some initial testing and VMWare for making experimental linux installations easier.

Update: BTW, the linux setup I used was ubuntu (after installing xubuntu packages to get xfce; should have started with xubuntu). Note that the transparency is similar to that on OS X and w32, i.e. a single alpha level for the entire window. Next up is to apply a per-pixel alpha mask, if I can scrounge up some samples of how to do it on each platform.

I added some features to JNA to facilitate working with the X11 visual lookups (it returns an array of structures), so a few more files got changed than just the examples jar. If you want the latest and greatest, you'll need to check out from CVS and do 'ant examples-jar'.


Anonymous said...

I need to make a shaped window to build a skinnable app, but i don´t know what to do to make it based on a color of a picture. I mean, i can´t make the shaped window based on Shape object since its VERY hard to describe the shape of the image.

How can i make just a determined color os the picture (the color that determine the invisible area of the window) have the alpha value of 0.0 and the other colors get the alpha value of 1.0?

Or, there is a way of creating a shape based on an image?

Luiz Grimuza,

technomage said...

Look at the API for WindowUtils. You can provide either a Shape or an Icon (e.g. ImageIcon). In the case of the Icon, the mask will consist of all pixels with a non-zero alpha component.

Silveira Neto said...

Cool! Finally I got a functional example of Java transparent windows on X. \o/

力豪 said...

My University project need
Java Transparent Windows.
But I never find better than yours.
Because another's not real transparent.
It's only use ROBOT take ScreenShot.

I want to reference your source code.
I don't use this in business.
Only use it in my project.
And if i finish my project,
I will show you.

My e-mail address:

And God bless you.

technomage said...

All source and binaries are available from