I have a JLabel with a box icon on it. I create the icon's image in photoshop. It's a png-24 image with the background full erased.
But when moved on top of a dark background, you can see that the background isn't fully transparent:
EDIT #2:
The image IS transparent. I've even gone through photoshop开发者_开发问答 tutorials to make sure I'm creating a transparent image the correct way. The problem seems to be with Java (and JLabels).
How do I fix this?
i've tested your image, it is not transparent. surely that is the reason.
<html>
<body style="background-color:#99cccc;">
<table>
<tr>
<th>your one isn't transparent</th>
<th>this one is</th></tr>
<tr>
<td><img src="http://i.stack.imgur.com/BvYxM.png" style="border:5px solid green;"/></td>
<td><img src="http://www.axdn.com/redist/axpssp_logo.png" style="border:5px solid green;"/></td></tr>
</table>
</body>
</html>
@Gabe: paste this into a html file and load it in a browser. This clearly isn't an issue with anything java related.
here's a java proof that your image isn't transparent AND that a proper transparent PNG works fine.
public static void main(String[] args) throws Throwable
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container cp = frame.getContentPane();
cp.setBackground(Color.RED);
cp.setLayout(new FlowLayout());
cp.add(new JLabel(new ImageIcon(new URL("http://i.stack.imgur.com/BvYxM.png"))));
cp.add(new JLabel(new ImageIcon(new URL("http://www.axdn.com/redist/axpssp_logo.png"))));
frame.pack();
frame.setVisible(true);
}
You may try with GIF format and set alpha value accordingly. I could not see your image right now. Well, make sure image that you are creating that is transparent. Otherwise you would not get it as you need.
sample guide for making transparent image: LINK
精彩评论