Keilly: Creating a Swing Dashboard Widget - Part 6 (Flipping)

Monday, June 2, 2008

Creating a Swing Dashboard Widget - Part 6 (Flipping)

When the info button is pressed the widget should flip over to reveal the back.
Using a flippable component to hold a blue front and green back, and hooking it up to the info button gives a very nice flipping transition, but with horrifying artifacts on OSX:

Also, on Windows the corners of the widget aren't transparent as expected:

After a little struggling I found that on Windows JPanels were causing the corner painting problem. Although marked as non-opaque their backgrounds were still being cleared to white every repaint! Turning off double buffering by passing false in the JPanel constructor fixed this:

OSX problems remain unresolved for now.


kumasawa said...

Did you see Joshua Marinacci's blog from today? He tells a different way to support translucent windows on Mac OS X:

frame.getRootPane().putClientProperty("Window.alpha", new Float(alpha));

Although, he says that it only works on Leopard.

Here is his blog

Keilly said...

Took a look and it's pretty cool but it controls the alpha value for the window *including all of its contents*.
So using it would make the widget itself semi-transparent, not what we were looking for but actually a nice effect.
I've fixed the OSX rendering problems separately. I'll post an update soon.

kumasawa said...

Ah... I should have read Marinacci's blog a little more carefully, as I didn't realize it would make the whole window translucent and not just the frame...