Translucent and shaped windows in JDK 7

May 3rd, 2009 | 6 Comments »

The latest weekly drop of JDK 7 (b57) has finally exposed the functionality of translucent and shaped windows as publicly supported APIs on the java.awt.Window class. Bug 6802853 has tracked the progress of exposing these APIs previously available in 6u10+ in the internal com.sun.awt.AWTUtilities class, and it’s time to update the examples to use the new public APIs.

To recap, here are the previous entries that used the AWTUtilities class:

All the source files referenced in these examples have been updated to use the new Window APIs, and here is a brief overview of the relevant API signatures:

  • AWTUtilities.isTranslucencySupported(Translucency) is now GraphicsDevice.isWindowTranslucencySupported(WindowTranslucency).
  • AWTUtilities.isTranslucencyCapable(GraphicsConfiguration) is now GraphicsConfiguration.isTranslucencyCapable().
  • AWTUtilities.setWindowShape(Window, Shape) is now Window.setShape(Shape).
  • AWTUtilities.setWindowOpacity(Window, float) is now Window.setOpacity(float).
  • AWTUtilities.setWindowOpaque(boolean) is superceded by Window.setBackground(Color). Passing the new Color(0, 0, 0, 0) achieves the old effect of installing per-pixel translucency.

You can see the Javadocs of the new Window methods in the corresponding Mercurial diff, or in the source archive bundled with the b57 installer.

Note that the com.sun.awt.AWTUtilities class is still there, and calling its API methods still produces the correct visuals. A quick look at the implementation reveals that the AWTUtilities methods do not (yet) go directly to the new Window methods, perhaps converging deeper in the AWT internals.


Related posts:

  1. Translucent and shaped windows in core Java I first spotted it about a month ago, and today’s build 12 of JDK 6.0u10...
  2. More tricks with translucent Swing windows The java.net site has just published my article on translucent and shaped windows, and it...
  3. Soft clipping and per-pixel translucency for Swing windows The entry on translucent and shaped windows in Swing has generated quite a lot of...
  4. Close your Swing / SWT windows in style Trident animation library allows adding a short fade-out sequence to a Swing / SWT window...


6 Comments on “Translucent and shaped windows in JDK 7”

  1. 1 Java desktop links of the week, May 4 | Jonathan Giles said at 3:10 pm on May 3rd, 2009:

    [...] Java 7 just got public API support for shaped and translucent windows , and Kirill Grouchnikov is kind enough to provide an overview of the changes. [...]

  2. 2 David said at 1:22 am on May 4th, 2009:

    And when will be JDK 7 released? ;)

  3. 3 Rémi Forax said at 6:45 am on May 4th, 2009:

    David, see
    http://weblogs.java.net/blog/forax/archive/2009/05/jdk7_milestones.html

  4. 4 wzberger said at 10:18 am on May 4th, 2009:

    Does the performance lack (http://forums.java.net/jive/thread.jspa?messageID=321379) still exist?

  5. 5 Kirill Grouchnikov said at 10:14 am on May 5th, 2009:

    Wolfgang – why not ask the AWT developers in the same thread?

  6. 6 wzberger said at 11:10 pm on May 5th, 2009:

    Sorry, just wanted to bother someone else ;-)
    I’ve already checked b57 and beside other (more important) issues the mentioned issue still exists.