Java Image Create createImageFromInvisibleComponent(JComponent component)

Here you can find the source of createImageFromInvisibleComponent(JComponent component)

Description

create Image From Invisible Component

License

Open Source License

Declaration

public static BufferedImage createImageFromInvisibleComponent(JComponent component) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;
import java.awt.Dimension;

import java.awt.Graphics2D;

import java.awt.GraphicsEnvironment;

import java.awt.image.BufferedImage;

import javax.swing.JComponent;

public class Main {
    public static BufferedImage createImageFromInvisibleComponent(JComponent component) {
        Dimension componentSize = component.getPreferredSize();
        component.setDoubleBuffered(false);
        component.setSize(componentSize);
        component.addNotify();/* w  ww . j  a v  a2  s . c o m*/
        component.validate();

        BufferedImage img = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration().createCompatibleImage(component.getWidth(), component.getHeight());
        Graphics2D grap = img.createGraphics();
        grap.setColor(Color.WHITE);
        grap.fillRect(0, 0, img.getWidth(), img.getHeight());
        component.print(grap);
        grap.dispose();
        return img;
    }
}

Related

  1. createImage(JPanel panel)
  2. createImage(String str)
  3. createImage(URL url, String description, boolean checkPresence)
  4. createImageCopy(Image image)
  5. createImageFromBase64String(String s)
  6. createImageFromVisibleComponent(JComponent comp, int cw, int ch)
  7. createImagePanel(Image image, Color backColor)
  8. getImage(Class clazz, String path)
  9. getImage(Component component)