Java Swing Icon createGrayIcon(Icon icon)

Here you can find the source of createGrayIcon(Icon icon)

Description

Creates a 'disabled' version of an icon.

License

Apache License

Parameter

Parameter Description
icon Icon to convert

Return

The 'grayed' version of the icon

Declaration

public static Icon createGrayIcon(Icon icon) 

Method Source Code

//package com.java2s;
/*/*from  www .  java  2  s.c  o  m*/
 *   Copyright 2007 skynamics AG
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

import javax.swing.GrayFilter;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Main {
    /**
     * Creates a 'disabled' version of an icon.
     *
     * @param icon Icon to convert
     * @return The 'grayed' version of the icon
     */
    public static Icon createGrayIcon(Icon icon) {
        Icon disabledIcon = null;

        if (icon instanceof ImageIcon)
            disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) icon).getImage()));

        return (disabledIcon != null) ? disabledIcon : icon;
    }
}

Related

  1. concatenateIcons(final Icon icon1, final Icon icon2)
  2. createBitmap(Icon icon)
  3. createChannelIcon(Icon ic)
  4. createColourIcon(int colour)
  5. createGrayIcon(Icon icon)
  6. createIcon(java.awt.Component component)
  7. createIcon(String resource)
  8. createIcon(URL resource)
  9. createIconFromResource(ClassLoader loader, String resourceName)