question: private void paintShadow ( final BufferedImage shadowBg , final Container layeredPane ) { final int layeredPaneWidth = layeredPane . getWidth ( ) ; final int layeredPaneHeight = layeredPane . getHeight ( ) ; if ( RECT . x + RECT . width > layeredPaneWidth ) { RECT . width = layeredPaneWidth - RECT . x ; } if ( RECT . y + RECT . height > layeredPaneHeight ) { RECT . height = layeredPaneHeight - RECT . y ; } if ( ! RECT . isEmpty ( ) ) { final Graphics g = shadowBg . createGraphics ( ) ; g . translate ( - RECT . x , - RECT . y ) ; g . setClip ( RECT ) ; if ( layeredPane instanceof JComponent ) { final JComponent c = ( JComponent ) layeredPane ; final boolean doubleBuffered = c . isDoubleBuffered ( ) ; c . setDoubleBuffered ( false ) ; c . paintAll ( g ) ; c . setDoubleBuffered ( doubleBuffered ) ; } else { layeredPane . paintAll ( g ) ; } g . dispose ( ) ; } }
target:  If needed paint dirty region of the snapshot