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;
@SuppressWarnings("restriction")
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
window1.add(text1);
window1.pack();
centerOnScreen(window1);
window1.setVisible(true);
window2.setUndecorated(true);
setTransparent(window2);
setAlpha(window2, 0.0f);
text2.setFont(new Font("Arial", 1, 60));
text2.setForeground(Color.red);
window2.add(text2);
window2.pack();
centerOnScreen(window2);
window2.setVisible(true);
// 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;
}
@Override
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;
}
break;
}
case 1: {
// fade in
if (++count < 100) {
setAlpha(window2, 0.01f * count);
} else {
phase = 2; // go to next phase
count = 0;
}
break;
}
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;
}
break;
}
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
}
break;
}
case 99:
System.exit(0);
}
}
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);
window.getRootPane().setOpaque(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);
}
}