Here you can find the source of disabledIcon(JComponent parent, Icon icon)
Parameter | Description |
---|---|
parent | the component on which the icon will be painted, can be <code>null</code> |
icon | an icon or <code>null</code> |
icon
or null
public static Icon disabledIcon(JComponent parent, Icon icon)
//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; } }