1 Reply Latest reply: Jun 26, 2013 2:23 AM by mKorbel RSS

    How to take a snap shot of a GUI in java

    user8557977

      Hi

       

         I know how to use Robot class to take a screen shot. But, I would like to take a snap shot of a java Swing GUI.  How can I do that....How can I know the locations of Java GUI in the screen.

       

      Please let me know

       

       

      Thanks

      Prashanth

        • 1. Re: How to take a snap shot of a GUI in java
          mKorbel

          there no needed any active Screens Capture

           

          any JComponents including Containers can be printed to Image, BufferedImage

           

                  Dimension size = container.getSize();

                  BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);

                  Graphics2D g2 = image.createGraphics();

                  panel.paint(g2);

                  try {

                      ImageIO.write(image, "jpg", new File("snapshot.jpg"));

                  } catch (Exception e) {

                      // exceptions handling

                  }