this is how I've done it. Just create a new instance of this class and pass in your TextArea. It redirects System.out and checks for messages on System.out every 5 seconds.
import java.io.*;
import javax.swing.*;
public class TextOut
implements Runnable
{
private JTextArea text;
private Reader in;
private Thread t;
public TextOut( JTextArea text )
throws Exception
{
this.text = text;
PipedOutputStream pout = new PipedOutputStream();
System.setOut( new PrintStream( pout ) );
in = new InputStreamReader( new PipedInputStream( pout ) );
t = new Thread( this );
t.start();
}
public void run()
{
while( true )
{
try
{
StringBuffer buffer = null;
while( in.ready() )
{
if ( buffer == null ) buffer = new StringBuffer();
buffer.append( (char)in.read() );
}
if ( buffer != null )
{
text.append( buffer.toString() );
java.awt.Rectangle r = new java.awt.Rectangle();
text.computeVisibleRect( r );
text.repaint( r );
}
t.sleep( 5000 );
} catch (IOException ioe) {
text.append( "" + ioe );
} catch (InterruptedException ie ) {
text.append( "" + ie );
}
}
}
}