Java Image sizeToImage(JComponent component, Image image)

Here you can find the source of sizeToImage(JComponent component, Image image)

Description

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

License

Open Source License

Parameter

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

Declaration

public static void sizeToImage(JComponent component, Image image) 

Method Source Code

//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);
        }
    }
}

Related

  1. setImage(Image im, JComponent c)
  2. setImageDimension(Image imagen)
  3. showImage(final String title, final Image image)
  4. showImage(Image image)
  5. showImage(Image image, String title)
  6. swapColor(Image image, Color imageColor, Color newColor)
  7. texturePaintHorizontal(JComponent parent, Graphics g, Image image, Rectangle areaToPaint)
  8. usesAlpha(Image image)
  9. verifyImageSizeBigger(byte[] imageData, int maxDim)