I noted that when i draw something with Color(0,0,0,0), which is over another image, the color shown is the JFrame background, not the image just below it.
Reasons that’d help me to find a solution?
Thanks!!
Edit: See the circles, the grey area (corners) should be transparent but are not, instead, they are the color of the JFrame.
alt text http://img72.imageshack.us/img72/9657/transparency.png
And here is the code to draw the circles:
public void paint(final Graphics g) {
super.paintComponent(g);
final Graphics2D g2 = (Graphics2D) g;
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (unitImage == null) {
unitImage = (BufferedImage) (createImage(30, 30));
final Graphics2D gc = unitImage.createGraphics();
gc.setRenderingHints(rh);
gc.setColor(outsideColor);
gc.fillOval(0, 0, diameter, diameter);
gc.setColor(middleColor);
gc.fillOval(diameter / 6, diameter / 6, (diameter / 3) * 2, (diameter / 3) * 2);
gc.setColor(innerColor);
gc.fillOval(diameter / 3, diameter / 3, diameter / 3, diameter / 3);
}
g2.drawImage(unitImage, null, 0, 0);
Been toying with the Alphacomposites, i think its not the solution. So i added all this new info which i believe, will help you guys to give me another tip.
@Chuk Lee is right: Unless you change it, the default
Graphics2Dcomposite isAlphaComposite.SrcOver. This handy tool displays the composite result for a selected rule and a specified pair of color and alpha.Addendum: One approach is to override
paintComponent()and render both map and circles, but you might be able to make the corners transparent by clearing the alpha:Does
createImage(30, 30)relate todiameter? For what component do you overridepaint()and invokesuper.paintComponent(g)?