Here you can find the source of sizeToImage(JComponent component, Image image)
Parameter | Description |
---|---|
component | the component to size |
image | the image to derive measurements from |
public static void sizeToImage(JComponent component, Image image)
//package com.java2s; import java.awt.Dimension; import java.awt.Image; import javax.swing.JComponent; public class Main { /**//from w w w. j ava 2s . c o m * Sizes a component based on the size of the provided image. * * @param component the component to size * @param image the image to derive measurements from */ public static void sizeToImage(JComponent component, Image image) { if (image != null) { int height = image.getHeight(null); int width = image.getWidth(null); Dimension d = new Dimension(width, height); component.setPreferredSize(d); } } }