Re: Transparent JDesktopPane



Oliver Wong wrote:
[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.

Thanks for that, Oliver. Looking more closely at the source code for JDesktopPane, I see that isOpaque is set to always return true. It looks as if they've decided to specifically bar the programmer from making these babies transparent, but forgot about the alpha channel possibilities. For now, I'm getting around it by ditching the whole JDesktopPane and just using JPanel derivatives. It works, but I would have liked to have it the other way.

Thanks again,
Luke
.



Relevant Pages

  • Re: Transparent JDesktopPane
    ... 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 [which is black), then the paint method would paint black pixels over the ghost image, and you'd get a completely black background. ... 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. ...
    (comp.lang.java.gui)
  • Re: Photos of Jan and Kidd !
    ... We're having some nice bug shows coming up that I am also looking ... Paint stripping is coming along nicely. ... using this household cleaner that strips paint quite well. ...
    (rec.autos.makers.vw.aircooled)
  • Re: WebBrowser edit mode redraw problem after paste
    ... I think this is a bug of IE. ... I can use Google's Docs & Spreadsheets to test it. ... some time it does not paint itself unless you press a key ... For some web site, it paints in the WebBrowser area ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Paint and Body....
    ... I am thinking of trying it on my bug. ... enamel paint that is for tractors and since it was cheap and so is my car I ... It just doesn't explain their price difference between ...
    (rec.autos.makers.vw.aircooled)
  • Re: Paint and Body....
    ... I am thinking of trying it on my bug. ... enamel paint that is for tractors and since it was cheap and so is my car I ... It just doesn't explain their price difference between ...
    (rec.autos.makers.vw.aircooled)