Hello everyone,
I've solved this problem with a bit of tricky programming, so in case anyone
else is wondering how to do this I'm going to post the solution here. It's
kind of a kludgy hack but it works.
Normally, to paint the icon, you would use this:
icon.paintIcon(c, g, x, y);
where c is the component, g is the Graphics2D context, etc.
To paint the highlighted icon, use this instead:
BufferedImage tmpImage = new BufferedImage(icon.getIconWidth(),
icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D tmpGfx = tmpImage.createGraphics();
icon.paintIcon(c, tmpGfx, 0, 0); //lay down the original icon
tmpGfx.setXORMode(new Color(0, 0, 80)); //replace this color with your
highlight color of choice
//this will make an area of solid highlight color wherever the icon was
painted (but not where it was transparent)
icon.paintIcon(c, tmpGfx, 0, 0);
tmpGfx.dispose(); //you must free up native resources
icon.paintIcon(c, g, x, y); //lay down original icon in our main gfx
context.
ImageIcon highlight = new ImageIcon(tmpImage);
Composite tempCmp = g.getComposite; //save the current composite
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
/*set the alpha blending, you can fiddle with the alpha value if you like*/
highlight.paintIcon(c, g, x, y); //overlay the highlight
g.setComposite(tempCmp); //restore the original composite.
That's it.
-Jeremy
> Hello,
> I have a class which extends JLabel, which is basically for an Icon View
[quoted text clipped - 14 lines]
> Thanks,
> -Jeremy