Java Icon createColorIcon(final int width, final int height, final Color color)

Here you can find the source of createColorIcon(final int width, final int height, final Color color)

Description

Create icon of given size and color.

License

Open Source License

Parameter

Parameter Description
width width.
height height.
color color.

Return

new icon.

Declaration

public static Icon createColorIcon(final int width, final int height, final Color color) 

Method Source Code


//package com.java2s;
/*//from w  w w  .  j  a  va  2  s  .  c o  m
 * IJ-Plugins
 * Copyright (C) 2002-2016 Jarek Sacha
 * Author's email: jpsacha at gmail dot com
 *
 *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Latest release available at http://sourceforge.net/projects/ij-plugins/
 */

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class Main {
    /**
     * Create icon of given size and color.
     *
     * @param width  width.
     * @param height height.
     * @param color  color.
     * @return new icon.
     */
    public static Icon createColorIcon(final int width, final int height, final Color color) {

        final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        final Graphics2D g = image.createGraphics();
        g.setColor(color);
        g.fillRect(0, 0, width, height);
        g.dispose();

        return new ImageIcon(image);
    }
}

Related

  1. createColorIcon(Color color)
  2. createHistImage(JComponent c, Icon hd, File dir, Color bgColor, String fname)
  3. createRotatedImage(Component c, Icon icon, double rotatedAngle)
  4. extractIconImage(Component component, Icon icon)
  5. genImageResource(Class cls, String icon)