Transparent JFrame using JNA

In Make JFrame transparent I had shown a way to making frame’s transparent using AWTUtilities class. But using that class results in access restriction compile time error, resolution in Eclipse is also shown in that post. Now here is the version using java natives. I have used Java Native Access (JNA) library to call native functions to get the things done.

Here WindowUtils class is provided in JNA jar (platform.jar). The method setWindowAlpha of WindowUtils classis used to make a window transparent. First argument of this method is your frame/window and second argument is alpha value. This class also has a method called setWindowTransparent, which can also be used to make window transparent .

Dependencies

You will need following 2 jars to run this program: (Both jar files are available to download on GitHub for JNA.)

jna.jar

platform.jar

To run above code on Windows, you will need to set “sun.java2d.noddraw” system property before calling the WindowUtils function.

System.setProperty("sun.java2d.noddraw", "true");

Output

Additional Notes

I have tested this code on following machines:

Windows XP service pack 3 (32 bit)

Windows 7 (32 bit)

Cent OS 5 (32 bit)

If you test it on other machines or have code for other machines using JNA for the same functionality then feel free to share it as comment to this post.

If you have successfully created pop up window then now you just need to add code of making it transparent. You have 2 ways to do it, one is using JNA and another is without using any external jar. Both ways are easy, just copy/paste the corresponding part of the code from my post to your frame.

And if you are looking for light box kind of thing then you should read my post about light box jar. You can easily find it in open source page.