private VolatileImage getImage(GraphicsConfiguration config, JComponent c, int w, int h, Object[] extendedCacheKeys) {
        ImageCache imageCache = ImageCache.getInstance();

        // get the buffer for this component
        VolatileImage buffer = (VolatileImage) imageCache.getImage(config, w, h, this, extendedCacheKeys);

        int renderCounter = 0; // to avoid any potential, though unlikely,

        // infinite loop
        do {

            // validate the buffer so we can check for surface loss
            int bufferStatus = VolatileImage.IMAGE_INCOMPATIBLE;

            if (buffer != null) {
                bufferStatus = buffer.validate(config);
            }

            // If the buffer status is incompatible or restored, then we need to
            // re-render to the volatile image
            if (bufferStatus == VolatileImage.IMAGE_INCOMPATIBLE || bufferStatus == VolatileImage.IMAGE_RESTORED) {

                // if the buffer is null (hasn't been created), or isn't the
                // right size, or has lost its contents,
                // then recreate the buffer
                if (buffer == null || buffer.getWidth() != w || buffer.getHeight() != h
                        || bufferStatus == VolatileImage.IMAGE_INCOMPATIBLE) {

                    // clear any resources related to the old back buffer
                    if (buffer != null) {
                        buffer.flush();
                        buffer = null;
                    }

                    // recreate the buffer
                    buffer = config.createCompatibleVolatileImage(w, h, Transparency.TRANSLUCENT);

                    // put in cache for future
                    imageCache.setImage(buffer, config, w, h, this, extendedCacheKeys);
                }

                // create the graphics context with which to paint to the buffer
                Graphics2D bg = buffer.createGraphics();

                // clear the background before configuring the graphics
                bg.setComposite(AlphaComposite.Clear);
                bg.fillRect(0, 0, w, h);
                bg.setComposite(AlphaComposite.SrcOver);
                configureGraphics(bg);

                // paint the painter into buffer
                paintDirectly(bg, c, w, h, extendedCacheKeys);

                // close buffer graphics
                bg.dispose();
            }
        } while (buffer.contentsLost() && renderCounter++ < 3);

        // check if we failed
        if (renderCounter == 3)
            return null;

        // return image
        return buffer;
    }
private VolatileImage getImage ( GraphicsConfiguration config , JComponent c , int w , int h , Object [ ] extendedCacheKeys ) { ImageCache imageCache = ImageCache . getInstance ( ) ; VolatileImage buffer = ( VolatileImage ) imageCache . getImage ( config , w , h , this , extendedCacheKeys ) ; int renderCounter = 0 ; do { int bufferStatus = VolatileImage . IMAGE_INCOMPATIBLE ; if ( buffer != null ) { bufferStatus = buffer . validate ( config ) ; } if ( bufferStatus == VolatileImage . IMAGE_INCOMPATIBLE || bufferStatus == VolatileImage . IMAGE_RESTORED ) { if ( buffer == null || buffer . getWidth ( ) != w || buffer . getHeight ( ) != h || bufferStatus == VolatileImage . IMAGE_INCOMPATIBLE ) { if ( buffer != null ) { buffer . flush ( ) ; buffer = null ; } buffer = config . createCompatibleVolatileImage ( w , h , Transparency . TRANSLUCENT ) ; imageCache . setImage ( buffer , config , w , h , this , extendedCacheKeys ) ; } Graphics2D bg = buffer . createGraphics ( ) ; bg . setComposite ( AlphaComposite . Clear ) ; bg . fillRect ( 0 , 0 , w , h ) ; bg . setComposite ( AlphaComposite . SrcOver ) ; configureGraphics ( bg ) ; paintDirectly ( bg , c , w , h , extendedCacheKeys ) ; bg . dispose ( ) ; } } while ( buffer . contentsLost ( ) && renderCounter ++ < 3 ) ; if ( renderCounter == 3 ) return null ; return buffer ; }
Gets the rendered image for this painter at the requested size, either
from cache or create a new one

@param  config            the graphics configuration.
@param  c                 the component to paint.
@param  w                 the component width.
@param  h                 the component height.
@param  extendedCacheKeys extended cache keys.

@return the new image.