synchronized void paintComponent(Graphics componentGraphics) {
        int width = getWidth();
        int height = getHeight();

        this.scrollController.updateModel(
                virtualTerminal.getBufferLineCount() * getFontHeight(),
                height);

        boolean needToUpdateBackBuffer =
                // User has used the scrollbar, we need to update the back buffer to reflect this
                lastBufferUpdateScrollPosition != scrollController.getScrollingOffset() ||
                        // There is blinking text to update
                        hasBlinkingText ||
                        // We simply have a hint that we should update everything
                        needFullRedraw;

        // Detect resize
        if(width != lastComponentWidth || height != lastComponentHeight) {
            int columns = width / getFontWidth();
            int rows = height / getFontHeight();
            TerminalSize terminalSize = virtualTerminal.getTerminalSize().withColumns(columns).withRows(rows);
            virtualTerminal.setTerminalSize(terminalSize);

            // Back buffer needs to be updated since the component size has changed
            needToUpdateBackBuffer = true;
        }

        if(needToUpdateBackBuffer) {
            updateBackBuffer(scrollController.getScrollingOffset());
        }

        ensureGraphicBufferHasRightSize();
        Rectangle clipBounds = componentGraphics.getClipBounds();
        if(clipBounds == null) {
            clipBounds = new Rectangle(0, 0, getWidth(), getHeight());
        }
        componentGraphics.drawImage(
                backbuffer,
                // Destination coordinates
                clipBounds.x,
                clipBounds.y,
                clipBounds.width,
                clipBounds.height,
                // Source coordinates
                clipBounds.x,
                clipBounds.y,
                clipBounds.width,
                clipBounds.height,
                null);

        // Take care of the left-over area at the bottom and right of the component where no character can fit
        //int leftoverHeight = getHeight() % getFontHeight();
        int leftoverWidth = getWidth() % getFontWidth();
        componentGraphics.setColor(Color.BLACK);
        if(leftoverWidth > 0) {
            componentGraphics.fillRect(getWidth() - leftoverWidth, 0, leftoverWidth, getHeight());
        }

        //0, 0, getWidth(), getHeight(), 0, 0, getWidth(), getHeight(), null);
        this.lastComponentWidth = width;
        this.lastComponentHeight = height;
        componentGraphics.dispose();
        notifyAll();
    }
synchronized void paintComponent ( Graphics componentGraphics ) { int width = getWidth ( ) ; int height = getHeight ( ) ; this . scrollController . updateModel ( virtualTerminal . getBufferLineCount ( ) * getFontHeight ( ) , height ) ; boolean needToUpdateBackBuffer = lastBufferUpdateScrollPosition != scrollController . getScrollingOffset ( ) || hasBlinkingText || needFullRedraw ; if ( width != lastComponentWidth || height != lastComponentHeight ) { int columns = width / getFontWidth ( ) ; int rows = height / getFontHeight ( ) ; TerminalSize terminalSize = virtualTerminal . getTerminalSize ( ) . withColumns ( columns ) . withRows ( rows ) ; virtualTerminal . setTerminalSize ( terminalSize ) ; needToUpdateBackBuffer = true ; } if ( needToUpdateBackBuffer ) { updateBackBuffer ( scrollController . getScrollingOffset ( ) ) ; } ensureGraphicBufferHasRightSize ( ) ; Rectangle clipBounds = componentGraphics . getClipBounds ( ) ; if ( clipBounds == null ) { clipBounds = new Rectangle ( 0 , 0 , getWidth ( ) , getHeight ( ) ) ; } componentGraphics . drawImage ( backbuffer , clipBounds . x , clipBounds . y , clipBounds . width , clipBounds . height , clipBounds . x , clipBounds . y , clipBounds . width , clipBounds . height , null ) ; int leftoverWidth = getWidth ( ) % getFontWidth ( ) ; componentGraphics . setColor ( Color . BLACK ) ; if ( leftoverWidth > 0 ) { componentGraphics . fillRect ( getWidth ( ) - leftoverWidth , 0 , leftoverWidth , getHeight ( ) ) ; } this . lastComponentWidth = width ; this . lastComponentHeight = height ; componentGraphics . dispose ( ) ; notifyAll ( ) ; }
Updates the back buffer (if necessary) and draws it to the component's surface
@param componentGraphics Object to use when drawing to the component's surface