At the risk of making a total fool of myself...
I got very excited when I discovered that Java's "only opaque rectangular windows" limitation has been removed. Full release is intended for Java 7, but working methods can be accessed thru com.sun.awt.AWTUtilities in recent releases of Java 6 (I'm using update 20).
I put together this little demo that adds some animation to the effects to give a hint of the potential. It runs for me under Windows 7 Home Premium; I just had to adjust Eclipse's compiler settings to warn rather then error for access rule violations.
I'd be very interested to hear anyone else's experience of these exciting new capabilities.

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;

import com.sun.awt.AWTUtilities;

public class DemoWindows implements ActionListener {

   public static void main(String[] args) {
      // create a new demo, and update it every 50 mSec
      new Timer(50, new DemoWindows()).start();

   int phase = 0; // demo runs a number of consecutive phases
   int count = 0; // each of which takes a number of timesteps
   JFrame window1 = new JFrame("Java windows demo");
   JLabel text1 = new JLabel("<HTML><H1>This is a demo of some of the effects"
         + "<BR>that can be achieved with the new Java"
         + "<BR>transparent window methods</H1>"
         + "<BR>(requires latest version of Java)");
   JFrame window2 = new JFrame("Java windows demo");
   JLabel text2 = new JLabel("<HTML><center>Java<BR>rocks");

   int w, h, r, x, y; // parameters of iris circle

   DemoWindows() {

      // build and diplay the windows

      setAlpha(window2, 0.0f);

      text2.setFont(new Font("Arial", 1, 60));

      // parameters of the smallest circle that encloses window2
      w = window2.getWidth();
      h = window2.getHeight();
      r = (int) Math.sqrt(w * w + h * h) / 2; // radius
      x = w / 2 - r; // top left coordinates of circle
      y = h / 2 - r;


   public void actionPerformed(ActionEvent e) {
      // called by timer 20 times per sec
      // goes thru a number of phases, each a few seconds long
      switch (phase) {
      case 0: {
         // initial pause
         if (++count > 50) {
            phase = 1; // go to next phase
            count = 0;
      case 1: {
         // fade in
         if (++count < 100) {
            setAlpha(window2, 0.01f * count);
         } else {
            phase = 2; // go to next phase
            count = 0;
      case 2: {
         // move
         if (++count < 160) {
            if (count <30 || count > 80) // pause for best effect
            window2.setLocation(window2.getX() +1, window2.getY() +1);
         } else {
            phase = 3; // go to next phase
            count = 0;
      case 3: {
         // iris out
         if (++count < r) {
            Shape shape = new Ellipse2D.Double(x + count, y + count, 
                  2 * (r - count),  2 * (r - count));
            setShape(window2, shape);
         } else {
            phase = 99; // go to final (exit) phase
      case 99:


   void centerOnScreen(JFrame window) {  // convenience method
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      window.setLocation((screenSize.width - window.getWidth()) / 2,
            (screenSize.height - window.getHeight()) / 2);

   void setTransparent(JFrame window) {
      // cover for temporary API expected to change for Java 7
      // should become: window.setBackground(new Color(0,0,0,0));
      AWTUtilities.setWindowOpaque(window, false);

   void setAlpha(JFrame window, float alpha) {
      // cover for temporary API expected to change for Java 7
      // should become: window.setOpacity(alpha);
      AWTUtilities.setWindowOpacity(window, alpha);
   void setShape(JFrame window, Shape shape) {
      // cover for temporary API expected to change for Java 7
      // should become window.setShape(Shape)
      AWTUtilities.setWindowShape(window, shape);

Recommended Answers

All 9 Replies

I'm interested to see what this looks like - could you post a screenshot of your application running?

I'm using Ubuntu at the moment and can't get it working. Will try it later on Windows 7 when I get a chance.

of app is thyast it animates transparent & shaped windows - so screenshot not very helpful! Let meknow how it goes on Win 7 for you.

Haven't had a chance to try Windows 7 just yet but I did do a few searches on this and found some documentation and example screen captures - transparent and shaped windows.

Not too sure about the animated part. What is being animated... the transition?

Yes. These refs are very useful:

I used a Swing Timer to animate fade in / move over desktop / shrink to a vanishing point - so much more interesting than just a static display.
I made a generalised version of this code as a utility class so now my spash screens fade out rather than vanishing, and my apps immediately look 2010 rather than 2004!

The second one I've already read as I found that one while searching myself. The first one is interesting. Thanks for the links.

I have another version of the demo that just displays a transparent .png (eg a splash screen) with fade in and iris out effects if you're interested. It also calls the temporary methods via Reflection as recommended in the second link - this also avoids access restriction problems with the latest 1.6 builds.

Update Nov '11...
Just to confirm that the APIs were released in Java 1.7 and work as expected.

I found this web site looking for some examples of Java Swing. Nice example. I just registered on Daniweb.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.