public static ImageIcon createOverlayIcon(final ImageIcon baseIcon,final ImageIcon overlayIcon){
  if (baseIcon == null) {
    throw new IllegalArgumentException("baseIcon must not be null!");
  }
  if (overlayIcon == null) {
    throw new IllegalArgumentException("overlayIcon must not be null!");
  }
  BufferedImage bufferedImg=new BufferedImage(baseIcon.getIconWidth(),baseIcon.getIconHeight(),BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2=(Graphics2D)bufferedImg.getGraphics();
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  AffineTransform identityAT=new AffineTransform();
  g2.drawImage(baseIcon.getImage(),identityAT,null);
  g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f));
  g2.drawImage(overlayIcon.getImage(),identityAT,null);
  g2.dispose();
  return new ImageIcon(bufferedImg);
}

public static ImageIcon createOverlayIcon ( final ImageIcon baseIcon , final ImageIcon overlayIcon ) { if ( baseIcon == null ) { throw new IllegalArgumentException ( "baseIcon must not be null!" ) ; } if ( overlayIcon == null ) { throw new IllegalArgumentException ( "overlayIcon must not be null!" ) ; } BufferedImage bufferedImg = new BufferedImage ( baseIcon . getIconWidth ( ) , baseIcon . getIconHeight ( ) , BufferedImage . TYPE_INT_ARGB ) ; Graphics2D g2 = ( Graphics2D ) bufferedImg . getGraphics ( ) ; g2 . setRenderingHint ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ; AffineTransform identityAT = new AffineTransform ( ) ; g2 . drawImage ( baseIcon . getImage ( ) , identityAT , null ) ; g2 . setComposite ( AlphaComposite . getInstance ( AlphaComposite . SRC_OVER , 1.0f ) ) ; g2 . drawImage ( overlayIcon . getImage ( ) , identityAT , null ) ; g2 . dispose ( ) ; return new ImageIcon ( bufferedImg ) ; }
paints the given overlay icon over the base icon . this can be used for example to cross out icons . provided the overlay icon has a transparent background , the base icon will still be visible .
