Java Swing UIManager disabledIcon(JComponent parent, Icon icon)

Here you can find the source of disabledIcon(JComponent parent, Icon icon)

Description

Gets a "disabled" icon according to the current look and feel.

License

Open Source License

Parameter

Parameter Description
parent the component on which the icon will be painted, can be <code>null</code>
icon an icon or <code>null</code>

Return

a disabled version of icon or null

Declaration

public static Icon disabledIcon(JComponent parent, Icon icon) 

Method Source Code

//package com.java2s;
/*//from w  ww  . j  a va2 s. c  o m
 * Bibliothek - DockingFrames
 * Library built on Java/Swing, allows the user to "drag and drop"
 * panels containing any Swing-Co
    
mponent the developer likes to add.
 * 
 * Copyright (C) 2007 Benjamin Sigg
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Benjamin Sigg
 * benjamin_sigg@gmx.ch
 * CH - Switzerland
 */

import java.awt.Graphics;

import java.awt.image.BufferedImage;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.UIManager;

public class Main {
    /**
     * Gets a "disabled" icon according to the current look and feel.
     * @param parent the component on which the icon will be painted, can be <code>null</code>
     * @param icon an icon or <code>null</code>
     * @return a disabled version of <code>icon</code> or <code>null</code>
     */
    public static Icon disabledIcon(JComponent parent, Icon icon) {
        if (icon == null)
            return null;

        Icon result = UIManager.getLookAndFeel().getDisabledIcon(parent, icon);
        if (result != null)
            return result;

        if (parent != null) {
            int width = icon.getIconWidth();
            int height = icon.getIconHeight();
            if (width > 0 && height > 0) {
                BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                Graphics g = image.createGraphics();
                icon.paintIcon(parent, g, 0, 0);
                g.dispose();
                icon = new ImageIcon(image);
                result = UIManager.getLookAndFeel().getDisabledIcon(parent, icon);
            }
        }

        if (result != null)
            return result;

        return icon;
    }
}

Related

  1. createMessageLabel(String message)
  2. createTabbedPane(int tabPlacement)
  3. decorateMissingValue(JComponent jComponent, boolean missingValueState)
  4. defaultColumnWidth()
  5. destylize(T comp)
  6. disablePaintSliderValue()
  7. drawVistaBackground(Graphics g, Component b, String prefix)
  8. fixGtkPopupStyle()
  9. fixHtmlDisplay(JComponent component)