question: public void paint ( Graphics g , Shape a ) { RSyntaxDocument document = ( RSyntaxDocument ) getDocument ( ) ; Rectangle alloc = a . getBounds ( ) ; tabBase = alloc . x ; host = ( RSyntaxTextArea ) getContainer ( ) ; Rectangle clip = g . getClipBounds ( ) ; clipStart = clip . x ; clipEnd = clipStart + clip . width ; lineHeight = host . getLineHeight ( ) ; ascent = host . getMaxAscent ( ) ; int heightBelow = ( alloc . y + alloc . height ) - ( clip . y + clip . height ) ; int linesBelow = Math . max ( 0 , heightBelow / lineHeight ) ; int heightAbove = clip . y - alloc . y ; int linesAbove = Math . max ( 0 , heightAbove / lineHeight ) ; int linesTotal = alloc . height / lineHeight ; if ( alloc . height % lineHeight != 0 ) { linesTotal ++ ; } Rectangle lineArea = lineToRect ( a , linesAbove ) ; int y = lineArea . y + ascent ; int x = lineArea . x ; Element map = getElement ( ) ; int lineCount = map . getElementCount ( ) ; int endLine = Math . min ( lineCount , linesTotal - linesBelow ) ; RSyntaxTextAreaHighlighter h = ( RSyntaxTextAreaHighlighter ) host . getHighlighter ( ) ; Graphics2D g2d = ( Graphics2D ) g ; Token token ; for ( int line = linesAbove ; line < endLine ; line ++ ) { Element lineElement = map . getElement ( line ) ; int startOffset = lineElement . getStartOffset ( ) ; int endOffset = lineElement . getEndOffset ( ) - 1 ; h . paintLayeredHighlights ( g2d , startOffset , endOffset , a , host , this ) ; token = document . getTokenListForLine ( line ) ; drawLine ( token , g2d , x , y ) ; y += lineHeight ; } }
target:  Actually paints the text area. Only lines that have been damaged are repainted.