List of usage examples for java.awt Component update
public void update(Graphics g)
From source file:Main.java
public static BufferedImage takeScreenShot(Component component, String... watermarks) { Dimension size = component.getSize(); BufferedImage screenshot = new BufferedImage(size.width, size.height, Transparency.OPAQUE); Graphics2D g = screenshot.createGraphics(); g.setClip(0, 0, size.width - 1, size.height - 1); component.update(g); FontMetrics fm = g.getFontMetrics(); int y = fm.getDescent(); for (String watermark : watermarks) if (watermark != null) { int x = size.width - SwingUtilities.computeStringWidth(fm, watermark); g.setColor(Color.black); g.drawString(watermark, x, y); g.setColor(Color.white); g.drawString(watermark, x - 1, y - 1); y -= fm.getHeight();/*from ww w .j av a 2 s . com*/ } g.dispose(); return screenshot; }