"C P via JavaKB.com" <forum@JavaKB.com> wrote.

Signature
"TFritsch$t-online:de".replace(':','.').replace('$','@')
Hi Thomas
Thanks. That really help with the "zen" of it all also.
>"C P via JavaKB.com" <forum@JavaKB.com> wrote.
>
[quoted text clipped - 9 lines]
>Try <http://www.google.de/search?q=System.setOut+%2Bswing>
>to find some implementations of this approach.
Rogan Dawes - 29 Jul 2005 14:28 GMT
> Hi Thomas
> Thanks. That really help with the "zen" of it all also.
[quoted text clipped - 14 lines]
>>Try <http://www.google.de/search?q=System.setOut+%2Bswing>
>>to find some implementations of this approach.
Try this approach:
Create a "DocumentOutputStream" class that implements OutputStream, and
writes everything to an encapsulated Document.
Then you can call "getDocument()" on your class, and
textField.setDocument() to link it to the GUI class.
It's about 20 lines of code, in all.
You can also vary the type of document to control how the text is
presented. e.g. using a StyledDocument, as each line is written to the
stream, you can highlight alternate lines, etc.
Rogan
Rogan Dawes - 29 Jul 2005 16:34 GMT
> Hi Thomas
> Thanks. That really help with the "zen" of it all also.
[quoted text clipped - 14 lines]
>>Try <http://www.google.de/search?q=System.setOut+%2Bswing>
>>to find some implementations of this approach.
Here is a link to an implementation. It is REALLY simple, as mentioned
in my other post.
Without the size-limiting, it probably WOULD be about 30 lines in total.
<http://cvs.sourceforge.net/viewcvs.py/owasp/webscarab/src/org/owasp/webscarab/ut
il/swing/DocumentOutputStream.java?rev=1.3&view=markup>
Then just wrap this with a PrintStream, and you are in business.
i.e.
DocumentOutputStream dos = new DocumentOutputStream();
Document document = dos.getDocument();
textArea.setDocument(document);
System.setErr(new PrintStream(dos));
Note that Document may be updated in non-Event-dispatching threads. From
the JavaDoc for AbstractDocument (from which PlainDocument is derived):
Any models subclassed from this class and used in conjunction with a
text component that has a look and feel implementation that is derived
from BasicTextUI may be safely updated asynchronously, because all
access to the View hierarchy is serialized by BasicTextUI if the
document is of type AbstractDocument. The locking assumes that an
independant thread will access the View hierarchy only from the
DocumentListener methods, and that there will be only one event thread
active at a time.
Regards,
Rogan