How do I obtain a java.awt.Image
of a JFrame?
I want to obtain a screen shot of a JFrame
(for later use within my application). This is presently accomplished using the robot to take a screen shot specifying the coordinates and dimensions of the JFrame
involved.
However, I believe that there is a better way: Swing components, by default, render themselves as images into a double buffer prior to painting themselves onto the screen.
Is there a way to obtain these images from the component?
ComponentImageCapture.java
Screen shot
See also
The code shown above presumes the component has been realized on-screen, prior to rendering.
Rob Camick shows how to paint an unrealized component in the Screen Image class.
Another thread that might be of relevance, is Render JLabel without 1st displaying, particularly the 'one line fix' by Darryl Burke.
LabelRenderTest.java
Here is an updated variant of the code shown on the second link.
Screen shot