Class ScreenshotTaker

java.lang.Object
org.fest.swing.image.ScreenshotTaker

public class ScreenshotTaker extends Object
Understands taking screenshots of the desktop and GUI components.
  • Field Details

  • Constructor Details

  • Method Details

    • saveDesktopAsPng

      public void saveDesktopAsPng(String imageFilePath)
      Takes a screenshot of the desktop and saves it as a PNG file.
      Parameters:
      imageFilePath - the path of the file to save the screenshot to.
      Throws:
      ImageException - if the given file path is null or empty.
      ImageException - if the given file path does not end with ".png".
      ImageException - if the given file path belongs to a non-empty directory.
      ImageException - if an I/O error prevents the image from being saved as a file.
    • takeDesktopScreenshot

      public BufferedImage takeDesktopScreenshot()
      Takes a screenshot of the desktop.
      Returns:
      the screenshot of the desktop.
      Throws:
      SecurityException - if readDisplayPixels permission is not granted.
    • saveComponentAsPng

      public void saveComponentAsPng(Component c, String imageFilePath)
      Takes a screenshot of the given Component and saves it as a PNG file.
      Parameters:
      c - the given component.
      imageFilePath - the path of the file to save the screenshot to.
      Throws:
      ImageException - if the given file path is null or empty.
      ImageException - if the given file path does not end with ".png".
      ImageException - if the given file path belongs to a non-empty directory.
      ImageException - if an I/O error prevents the image from being saved as a file.
    • takeScreenshotOf

      public BufferedImage takeScreenshotOf(Component c)
      Takes a screenshot of the given Component.
      Parameters:
      c - the given component.
      Returns:
      a screenshot of the given component.
      Throws:
      SecurityException - if readDisplayPixels permission is not granted.
    • takeScreenshot

      private BufferedImage takeScreenshot(Rectangle r)
    • findFocusOwnerAndHideItsCaret

      @RunsInEDT private static JTextComponent findFocusOwnerAndHideItsCaret()
    • takeScreenshot

      private static BufferedImage takeScreenshot(Robot robot, Rectangle r)
    • showCaretIfPossible

      private void showCaretIfPossible(JTextComponent textComponent)
    • showCaretOf

      @RunsInEDT private static void showCaretOf(JTextComponent textComponent)
    • saveImage

      public void saveImage(BufferedImage image, String filePath)
      Save the given image as a PNG file.
      Parameters:
      image - the image to save.
      filePath - the path of the file to save the image to.
      Throws:
      ImageException - if the given file path is null or empty.
      ImageException - if the given file path does not end with ".png".
      ImageException - if the given file path belongs to a non-empty directory.
      ImageException - if an I/O error prevents the image from being saved as a file.
    • validate

      private void validate(String imageFilePath)