How to use glassPane to create transparent window?

Okay, so I wanna make a Java JFrame that is transparent, but than has a the glassPane not transparent so I can make my own style of windows. can this be done?

Try here :wink:

I have googled it :
I wouldn’t be asking if I didn’t lol.

I’m confused; the very first link from Google gives you an exhaustive explanation of how translucent windows (including demos!) are implemented in Java?

An updated version of the tutorial can be found here.

AWTUtilities isn’t used anymore T_T

PS does Java 1.7 have anything new for transparent windows and other eye-candy?

This has example code for both Java 6 and 7: http://www.pushing-pixels.org/?p=1886

I just bit the bullet and used AWTUtils. Now I have a new problem though:

I’m trying to draw a solid red oval on a transparent window. I later want to do something more complex with multiple shapes, so using setWindowShape isn’t what I’m looking for. This is the code I’m using so far:



import java.awt.*;
import javax.swing.*;

public class JavaDock extends JFrame{

    public JavaDock(){
        super("This is a test");

        setSize(400, 150);

        setUndecorated(true);
        getContentPane().setLayout(new FlowLayout()); 
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         JPanel panel = new JPanel()  
         {  
            public void paintComponent(Graphics g)  
            {  
               Graphics2D g2d = (Graphics2D) g.create();
               g2d.setComposite(AlphaComposite.Clear);
               g.setColor(Color.red);  

               //Draw an oval in the panel  
               g.fillOval(10, 10, getWidth() - 20, getHeight() - 20);  
            }  
         }; 

        panel.setOpaque(false);
        setGlassPane(panel);  
        getGlassPane().setVisible(true);
        com.sun.awt.AWTUtilities.setWindowOpacity(this, 0.5f);
        setVisible(true);
    }

     protected void paintComponent(Graphics g) {

        }

     public static void main(String[] args){
         JavaDock jd = new JavaDock();
     }
}

bump

Good info here: http://download.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html

About soft clipping: http://www.pushing-pixels.org/?p=272

If you want to use a JNA library instead (to allow older Java versions) read: http://rabbit-hole.blogspot.com/

I believe SWT also has such features too.