import java.awt.AWTException; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.Insets; import java.awt.Rectangle; import java.awt.Robot; import java.awt.image.BufferedImage; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JRootPane; public class SimpleTransFrame3 extends JFrame { private Robot robot; private BufferedImage image; private Watcher watcher; public SimpleTransFrame3() { super(); } public SimpleTransFrame3(String title) { super(title); init(); } public SimpleTransFrame3(GraphicsConfiguration gc) { super(gc); init(); } public SimpleTransFrame3(String title, GraphicsConfiguration gc) { super(title, gc); init(); } private void init() { try { robot = new Robot(); } catch (AWTException ex) { ex.printStackTrace(); return; } setRootPane(new ImageRootPane()); JComponent content = (JComponent)getContentPane(); content.setOpaque(false); watcher = new Watcher(); watcher.start(); } public synchronized boolean getIgnoreRepaint() { watcher.wakeup(); return super.getIgnoreRepaint(); } public void addNotify() { super.addNotify(); watcher.wakeup(); } private void copyScreen() { Rectangle bounds = getBounds(); Insets insets = getInsets(); bounds = new Rectangle(bounds.x + insets.left, bounds.y + insets.top, bounds.width - insets.left - insets.right, bounds.height - insets.top - insets.bottom); hide(); image = robot.createScreenCapture(bounds); show(); } class ImageRootPane extends JRootPane { public void paintComponent(Graphics g) { g.drawImage(image, 0, 0, this); } } class Watcher extends Thread { public synchronized void wakeup() { notifyAll(); } public void run() { try { while(true) { synchronized (this) { wait(); } copyScreen(); } } catch (InterruptedException ex) { return; } } } public static void main(String[] args) { JFrame frame = new SimpleTransFrame3("Capture Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new FlowLayout()); frame.getContentPane().add(new JButton("Button")); frame.setBounds(100, 100, 400, 200); frame.setVisible(true); } }