Does anyone know how to take a screen shot of a JFrame or any Java Swing application which is NOT visible?
jframeobj.setVisible(false);
Something to extract the information from the memory itself?
Does anyone know how to take a screen shot of a JFrame or any Java Swing application which is NOT visible?
jframeobj.setVisible(false);
Something to extract the information from the memory itself?
Short answer: yes — but not with Robot or an OS screenshot. As pointed out, Robot only captures visible pixels. What and were hinting at is to render the Swing UI into an offscreen image yourself: layout the component tree on the EDT, paint it into a BufferedImage, and save that image. That produces a "virtual screen" capture without making the window visible.
Do this on the Event Dispatch Thread, size/validate the component tree, create a BufferedImage, call the component's printing/painting method, then write the image. Example steps:
// on EDT (invokeAndWait/invokeLater)
frame.setSize(w,h); // or set sizes of components
frame.validate(); // layout children
BufferedImage img = new BufferedImage(frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = img.createGraphics();
frame.getContentPane().printAll(g); // paint into offscreen image
g.dispose();
ImageIO.write(img, "png", new File("out.png")); Caveats: some heavyweight components or native-dependent UI delegates may not render correctly until their UI is initialized; to avoid surprises set the LookAndFeel before creating components and validate/layout before painting. On headless JVMs some top-level operations throw HeadlessException, so check GraphicsEnvironment.isHeadless() first. For API details see the JComponent and BufferedImage docs (javax.swing.JComponent, java.awt.image.BufferedImage).
Jump to Post— jwenting 1,905SCREENshot, that's a recording of what's visible on the SCREEN.
Something invisible will not be on one.
SCREENshot, that's a recording of what's visible on the SCREEN.
Something invisible will not be on one.
Yes but there is something called as virtual screen. So I was wondering if java could capture that?
In that case you would have to create your own virtual screen by making those components visible.
errr... if you want to take the screenshot of something that's invisible, then make it as visible, and then say that this is invisible???? lol... that's the best idea i can give you :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.