0

I have created a simple icon in Gimp2 and converted it, so I can display it on a label.

The icon is this:

public static final byte[] RedButton16 = 
{
    71, 73, 70, 56, 57, 97, 16, 0, 
    16, 0, -95, 2, 0, 0, 0, 0, 
    -1, 0, 0, -1, -1, -1, -1, -1, 
    -1, 33, -7, 4, 1, 10, 0, 2, 
    0, 44, 0, 0, 0, 0, 16, 0, 
    16, 0, 0, 2, 37, -108, 29, -87, 
    113, -67, -97, 28, -124, 6, 76, 42, 
    -18, -76, -6, -15, -82, 124, 96, 32, 
    -126, 101, 119, 106, 64, -118, -79, 79, 
    -27, 70, -57, -102, 2, -51, 76, -45, 
    119, 1, 0, 59
};

To load the icon into the label I use this code:

private ImageIcon getRedIcon()
{
    if(MainPanel.mRedIcon == null)
        MainPanel.mRedIcon = new ImageIcon(GUIIcons.RedButton16);

    return MainPanel.mRedIcon;
}

foo()
{
    mStatusLabel.setIcon(getRedIcon());
}

I can see the icon on the screen, but the color is wrong. When I view it with an external viewer it looks as I created it. Either red or green (I have two versions, both are GIF files) and both have the same problem. I assume that there might be a problem with the alpha channel, but I have no idea whats wrong and how to fix it, or how Java inteprets the data. Do I have to fix the image, or do I have to set some options on the Imageloader?

update

I uploaded the images here. How I created them and how they look on screen in my Java application.

Screenshot green

Correct green

Screenshot red

Correct red

Devolus
  • 21,661
  • 13
  • 66
  • 113

1 Answers1

2

Assuming you did not make a mistake when you tranlated the image to a byte array in source code, this looks more like Swing rendered the Icon in disabled state.

I suspect you disabled the label somewhere with setEnabled(false), causing it to render in disabled state. You can check this easily by setting a text on the label, if it appears ghosted the label is disabled.

Durandal
  • 19,919
  • 4
  • 36
  • 70
  • AAAAHHH! How stupid! You are right, I had used a button before that and disabled it and left the statement in. Now it works! :) Thanks! – Devolus May 29 '13 at 11:18