public void appendLine ( String line ) { if ( count >= nlines ) { try { int remove = Math . max ( removeIncr , count - nlines ) ; // nlines may have changed int offset = ta . getLineEndOffset ( remove ) ; ta . replaceRange ( "" , 0 , offset ) ; } catch ( Exception e ) { log . error ( "Problem in TextHistoryPane" , e ) ; } count = nlines - removeIncr ; } ta . append ( line ) ; ta . append ( "\n" ) ; count ++ ; // scroll to end ta . setCaretPosition ( ta . getText ( ) . length ( ) ) ; }
Append this line to the bottom of the JTextArea . A newline is added and JTextArea is scrolled to bottom ; remove lines at top if needed .