Re: Transparent JDesktopPane




"Luke Webber" <luke@xxxxxxxxxxxxx> wrote in message news:44a29e5a_7@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
I was so very happy today, because I had my UI looking just really blody flash. Then I tried moving a JInternalFrame, and the whole house of cards tumbled down.

My whole L&F depends on having a JPanel in the background of an MDI form. That background panel has a tiled image of a cute little watermark. Buttons on the left, JDesktop taking up the rest of the space, with JInternal frames popping up as required.

As I said in my opening paragraph, the problem is that moving the JInternalFrames about leaves a mess behind on the JDesktopPane.

I've put together a simple class that shows my problem exactly. It'll wrap, but it's also available for download at...

http://www.webber.com.au/pub/TransparentMDI.java

I'd greatly appreciate any thought on this. The sample code is below.

[program snipped]

It looks like a bug in the paint() method of javax.swing.JLayeredPane. Basically, the code as written seems to assume that the background colour is not translucent at all, and so when it needs to "repaint" an area, it simply gets its own background colour, and paints it over the area that needs to be updated.

What's happening in your program is that when you move your JInternalFrame, there's now an old ghost-image of the JInternalFrame that needs to be painted over. If you had used a fully opaque colour like (0,0,0,255) [which is black), then the paint method would paint black pixels over the ghost image, and you'd get a completely black background.

Unfortunately, you're using the colour (0,0,0,32) which is a translucent black, so the ghost image is still visible undernearth the tranluscent black paint.

You might want to file a bug report with Sun, including your demonstration program, but I'm not sure if Sun will fix it, or just say that's the way it was designed to work.

In the meantime, you might fix it by having it so that whenever the JDesktopPane needs to repaint itself, it triggers a call to the JPanel pnlMain underneath it to paint first. So what will happen is that the pnlMain will overwrite the ghost image with red paint, and then the JDesktopPane will apply its translucent black paint over the newly applied red paint.

- Oliver

.


Quantcast