public static BufferedImage doScreenshot(JComponent component) {
    int width = component.getWidth();
    int height = component.getHeight();
    BufferedImage screenshot = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = screenshot.createGraphics();
    component.paint(graphics2D);
    return screenshot;
}