Wait a second; I've got something for that. <dig dig shuffle shuffle> Ah!
Here it is:public class TextAreaOutputStream extends OutputStream {
private static final int TABSTOP= 4;
private static final int SIZE= 0x8000;
private static final boolean WORDWRAP= true;
private static final int ROWS= 24;
private static final int COLS= 80;
protected JTextArea ta;
public TextAreaOutputStream() { this(new JTextArea(ROWS, COLS)); }
public TextAreaOutputStream(JTextArea ta) { this(ta, TABSTOP, WORDWRAP); }
public TextAreaOutputStream(JTextArea ta, int tabstop, boolean wordwrap) {
this.ta= ta;
initialize(tabstop, wordwrap, false);
}
private void initialize(int tabstop, boolean wordwrap, boolean editable) {
ta.setTabSize(tabstop);
ta.setWrapStyleWord(wordwrap);
ta.setEditable(editable);
}
protected void append(String text) {
int lt= text.length();
synchronized(ta) {
if (lt >= SIZE) {
ta.setText(text);
return;
}
String buf= ta.getText();
int i= 0;
lt+= buf.length();
for (int j= 0; lt-i >= SIZE; i= j+1)
if ((j= buf.indexOf('\n', i)) < 0)
break;
if (lt-i >= SIZE)
ta.setText(buf= text);
else
ta.setText(buf= buf.substring(i)+text);
ta.setCaretPosition(buf.length());
}
}
public JTextArea getJTextArea() { return ta; }
public void write(int b) { append(""+((char)b)); }
public void write(byte b[]) { write(b, 0, b.length); }
public void write(byte b[], int ofs, int len) { append(new String(b, ofs, len)); }
}
Simply hook this up to a System.out or Sytem.err stream and you're in business.
kind regards,
Jos
> I have something like this at home but can't get to
> it now.
>
> Basically you want to make a TextAreaOutputStream
> that outputs everything to a given textarea (you can
> find examples of this on the internet) and then use
> System.setOut(...) with your stream
So it is posible to show something lite target with System.setOut(..) and just use System.out to print in that component?