Here you can find the source of scaleIcon(final ImageIcon icon)
Parameter | Description |
---|---|
icon | ImageIcon to scale |
public static Icon scaleIcon(final ImageIcon icon)
//package com.java2s; /*/*w w w .j a va2 s . c o m*/ * jGnash, a personal finance application * Copyright (C) 2001-2015 Craig Cavanaugh * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Image; import javax.swing.Icon; import javax.swing.ImageIcon; public class Main { private static float growthPercentage = 1f; /** * Returns a scaled icon based on the reduced font size * * @param icon {@code ImageIcon} to scale * @return the scaled {@code Icon} */ public static Icon scaleIcon(final ImageIcon icon) { int scaledWidth = (int) Math.floor(icon.getIconWidth() * growthPercentage); int scaledHeight = (int) Math.floor(icon.getIconHeight() * growthPercentage); Image scaledInstance = icon.getImage().getScaledInstance(scaledWidth, scaledHeight, java.awt.Image.SCALE_SMOOTH); return new ImageIcon(scaledInstance); } }