Drawing a Component to BufferedImage causes display corruption
===

I am using the `JScrollNavigator` component described [here][1], in order to provide a navigation window onto a large "canvas-like" CAD component I have embedded within a `JScrollPane`.

I have tried to adapt the `JScrollNavigator` to draw a thumbnail image of the canvas to provide some additional context to the user.  However, the action of doing this causes the rendering of my application's main frame to become corrupted.  Specifically, it is the action of calling `paint(Graphics)` on the viewport component (i.e. my main canvas), passing in the `Graphics` object created by the `BufferedImage` that causes subsequent display corruption; if I comment this line out everything works fine.

Below is the JScrollNavigator's overridden `paintComponent` method:


    @Override
    protected void paintComponent(Graphics g) {
        Component view = jScrollPane.getViewport().getView();
        BufferedImage img = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = img.createGraphics();

        // Paint JScrollPane view to off-screen image and then scale.
        // It is this action that causes the display corruption!
        view.paint(g2d);
        g2d.drawImage(img, 0, 0, null);
        Image scaled = img.getScaledInstance(getWidth(), getHeight(), 0);

        g.drawImage(scaled, 0, 0, null);
        super.paintComponent(g);
    }

Does anyone have any suggestions as to the cause of the corruption?  I would have thought that painting to an offscreen image should have no effect on existing paint operations.

  [1]: http://www.javalobby.org/java/forums/t21355.html