Here you can find the source of createColorIcon(final int width, final int height, final Color color)
Parameter | Description |
---|---|
width | width. |
height | height. |
color | color. |
public static Icon createColorIcon(final int width, final int height, final Color color)
//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); } }