JFrame decorated + transparent icon

The image tells everything doesn’t it?

Transparency (just a bitmask) is ok as long as the JFrame isn’t decorated. If it’s decorated the “bounding box” of the icon is gray instead of having that primary1(or so) color.

I guess the fix would be a two liner… setColor + fillRect.

Or is it supposed to be like that? :>

Looks like a bug to me. File a report.

Ye… blee… it’s filed.

But I guess that wasn’t worth the pain.

Could you please post the code you use?
Is that a GIF image?

Could you please post the code you use?

Ofcorse.

[...]
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.net.URL;
import java.util.Random;
import javax.swing.*;

public class GUI extends JFrame
{
   [...]
   public GUI()
   {
      super("Ludo");
      [...]
      this.setIconImage(ImageLoader.load("icon.gif"));
[...]

and the loader:


import java.io.*;
import java.net.*;
import javax.imageio.*;
import java.awt.image.*;

public class ImageLoader
{
   public static BufferedImage load(String name)
   {
      BufferedImage image;
      try
      {
         URL imageUrl = ImageLoader.class.getResource("/gfx/"+name);
         image = ImageIO.read(imageUrl);
      }
      catch(IOException ioe)
      {
         GUI.dm.printErr("couldn't load \"/gfx/icon.gif\"");
         image=null;
      }
     return image;
   }
}

Is that a GIF image?

Yes.

I didn’t anything stupid did I?

Does the same problem occur if you use Toolkit.[get|create]Image?

Sounds like another ImageIO-gif-transparency bug to me… errr though that doesn’t explain why it works fine with undecorated Swing :-/

/me is confused

… unless ofcourse the image is rendered differently(natively?) on undecorated frames.

/me is still confused

Does the same problem occur if you use Toolkit.[get|create]Image?

Yes.

setIconImage(Toolkit.getDefaultToolkit().createImage((CG_MainFrame.class).getResource("/gfx/x.gif")));

Same **** different method :slight_smile:

Oh and I won’t try it with a “proper” (like you like to call it) Toolkit.

Well… I think that the trasparency actually works, but the background is set to the wrong color (that ugly I don’t need a color default gray).

Btw the bug is also visible in one of the demo applications:

demo/jfc/Metalworks/Metalworks.jar

Theme->Presentation and you can see it clearly.

Yeah, I can see the bug in Metalworks now…

This bug is related to the way the context menus of JFrame titlebars are created. The MetalTitlePane class - which is responsible for painting the titlebar - has a system menu which is derived from JMenuBar.

It is created with default opacity, i.e. true. Therefore the icon is painted opaque which implies a fully painted background in the default JMenuBar background color.

At least for the Tonic look and feel, I have fixed this bug by setting the opacity of the system menu to false:

http://www.digitprop.com/images/lf/transparency01.gif

http://www.digitprop.com/images/lf/transparency02.gif

For Metal and other L&F’s, it should be possible to dig down into the component hierarchy of the JFrame, and manually set the opacity of the system menu bar. However, this is bound to break as soon as Sun changes the component hierarchy, of course. Alternatively one could create a custom L&F derived from Metal, with everything left unchanged except for MetalRootPaneUI (which creates the title bar).

Thanks for taking a look :slight_smile:

Best thing ever ;D

/me says YES to cute icons!