Container クラスのスクリーンショットを録る

ある Container vv に表示されている内容を format 形式で filename というファイルに書き出す。

public void writeImage(Container vv, String format, String filename) throws IOException
{
        // capture: create a BufferedImage
        BufferedImage bi = new BufferedImage(vv.getSize().width, vv.getSize().height, BufferedImage.TYPE_INT_BGR);
        // create the Graphics2D object that paints to it
        Graphics2D g = bi.createGraphics();
        vv.paintAll(g);

        g.setColor(Color.BLACK);
        g.drawString("Suffix Tree for '" + getBodyString() + "'", 20, 20);

        //  and save out the BufferedImage
        ImageIO.write(bi, format, new File(filename));
}

vv.paintALL(g);

vv.paintComponents(g);

と書くと、Container vv に含まれているコンポーネントを描画し、vv 自身を描画しない。