Java Swing Icon sizeToIcon(JComponent component, Icon icon)

Here you can find the source of sizeToIcon(JComponent component, Icon icon)

Description

Sizes a component based on the size of the provided icon.

License

Open Source License

Parameter

Parameter Description
component the component to size
icon the icon to derive measurements from

Declaration

public static void sizeToIcon(JComponent component, Icon icon) 

Method Source Code

//package com.java2s;

import java.awt.Dimension;

import javax.swing.Icon;

import javax.swing.JComponent;

public class Main {
    /**/*from   w ww . j av  a  2  s .  co m*/
     * Sizes a component based on the size of the provided icon.
     * 
     * @param component the component to size
     * @param icon the icon to derive measurements from
     */
    public static void sizeToIcon(JComponent component, Icon icon) {
        if (icon != null) {
            int height = icon.getIconHeight();
            int width = icon.getIconWidth();

            Dimension d = new Dimension(width, height);
            component.setPreferredSize(d);
        }
    }
}

Related

  1. mergeIcons(Icon i1, Icon i2, int offsetRechtsOben)
  2. reescala(Icon ic, int maxW, int maxH)
  3. resize(Icon icon, int width, int height)
  4. scaleDown(Icon icon, int maxWidth, int maxHeight)
  5. setComponentTabIcon(Component component, Icon icon)