Here you can find the source of grayIcon(Icon icon)
public static ImageIcon grayIcon(Icon icon)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from ww w.j av a 2 s. c o m * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.awt.Graphics; import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.ColorConvertOp; import javax.swing.Icon; import javax.swing.ImageIcon; public class Main { /** * Make grascale using a {@link ColorConvertOp} */ public static ImageIcon grayIcon(Icon icon) { if (icon == null || !(icon instanceof ImageIcon)) { return null; } BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = image.createGraphics(); g.drawImage(((ImageIcon) icon).getImage(), 0, 0, null); g.dispose(); ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); return new ImageIcon(op.filter(image, image)); } }