private class TextAreaOutputStream extends FilterOutputStream {
private JTextArea textArea;
public TextAreaOutputStream(JTextArea textArea) {
super(new ByteArrayOutputStream());
this.textArea = textArea;
}
public void write(byte b[]) throws IOException {
textArea.append(new String(b));
}
public void write(byte b[], int off, int len) throws IOException {
textArea.append(new String(b, off, len));
}
}
logTextArea = new JTextArea();
PrintStream logPrintStream = new PrintStream(new TextAreaOutputStream(
logTextArea));
System.setErr(logPrintStream);
System.setOut(logPrintStream);
Search This Blog
Java: Redirect System.out and System.err to a JTextArea component
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment