Example usage for javax.swing JPanel prepareImage

List of usage examples for javax.swing JPanel prepareImage

Introduction

In this page you can find the example usage for javax.swing JPanel prepareImage.

Prototype

public boolean prepareImage(Image image, ImageObserver observer) 

Source Link

Document

Prepares an image for rendering on this component.

Usage

From source file:Capture.java

public static void main(String[] args) {
    JFrame capture = new JFrame();
    capture.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Toolkit kit = Toolkit.getDefaultToolkit();
    final Dimension d = kit.getScreenSize();
    capture.setSize(d);//from  w ww .j  a  va  2  s  . c  o m

    Rectangle rect = new Rectangle(d);
    try {
        Robot robot = new Robot();
        final BufferedImage image = robot.createScreenCapture(rect);
        image.flush();
        JPanel panel = new JPanel() {
            public void paintComponent(Graphics g) {
                g.drawImage(image, 0, 0, d.width, d.height, this);
            }
        };
        panel.setOpaque(false);
        panel.prepareImage(image, panel);
        panel.repaint();
        capture.getContentPane().add(panel);
    } catch (Exception e) {
        e.printStackTrace();
    }

    capture.setVisible(true);
}