Here you can find the source of sizeToIcon(JComponent component, Icon icon)
Parameter | Description |
---|---|
component | the component to size |
icon | the icon to derive measurements from |
public static void sizeToIcon(JComponent component, Icon icon)
//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); } } }