How to Create Translucent and Shaped Windows in java.

Hi all,

I am back after a long time. This time I want to tell you all how I set a window as translucent in java. It was a very cumbersome thing to do before recently. From JDK 6 update 10, java has this facility to set the window as translucent  and its very easy.

Recently I did this in one of my projects and wanted to share it with you all.

As of the Java Platform, Standard Edition 6 (Java SE 6) Update 10 release, we can add translucent and shaped windows to our Swing applications.

The translucent and shaped window API was first added to the Java SE 6 Update 10 release as a private API. This functionality was moved to the public AWT package in the JDK 7 release.

Here is an example :

import java.awt.*;
import javax.swing.*;
import static java.awt.GraphicsDevice.WindowTranslucency.*;

public class MyWindow extends JFrame {
    public MyWindow() {
        setLayout(new GridBagLayout());


        add(new JButton("Just a Button"));

    public static void main(String[] args) {
        // Determine if the GraphicsDevice supports translucency.
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 GraphicsDevice gd = ge.getDefaultScreenDevice();

        //If translucent windows aren't supported, exit.
        if (!gd.isWindowTranslucencySupported(TRANSLUCENT)) { 
 System.err.println( "Translucency is not supported"); 

        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                MyWindow tw = new MyWindow();

		// Set the window to 55% opaque (45% translucent).

		// Display the window.

To learn more please check this link.


Here is how you can select which methods to use according to your JDK version.


Manohar Bhattarai (मनोहर भट्टराई)
Twitter :- :-

I am Manohar Bhattarai, a vivid java programmer. I am a keen Linux user. I currently boot Ubuntu Linux. I am a Free/Libre Open Source Software enthusiast.

Posted in Java, java 7, jdk7, Swing Tagged with: , , , , , , , , , , , , , , , , , , , , ,
2 comments on “How to Create Translucent and Shaped Windows in java.
  1. geox says:

    That is the proper blog for anybody who needs to find out about this topic. You realize so much its virtually exhausting to argue with you (not that I really would need…HaHa). You undoubtedly put a brand new spin on a subject thats been written about for years. Great stuff, just nice!

  2. hermes says:

    I love blogs and i also can tell you additionally like blogs.

2 Pings/Trackbacks for "How to Create Translucent and Shaped Windows in java."
  1. Free says:

    […]in this page you can find our links to articles , we noticed these are worth visiting[…]…

  2. code sharing says:

    add your code…

    […]How to Create Translucent and Shaped Windows in java. « Manohar Bhattarai[…]…

Leave a Reply