• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reassigning System.out to display in a JTextArea

 
Christopher Elkins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a GUI application and one of the requirements is that the System.out stream be displayed in a JTextArea at the bottom of the form. I've tried every way I can think of to reassign the output stream, but to no avail. Can anyone help me out with this? Thanks.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do System.setOut( somePrintStream ). Try extending printstream in your own class. You have to override a bunch of methods so they all pass data to some object that appends the JTextArea. I extended PrintStream for my logger so I could do exception.printStackTrace(Logger.getStream()).

Hmmm, I thought you might be able to do something with PipedStream but PrintStream is a concrete class, not an interface, so you seem to be prevented from doing that. Bummer.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christopher, did you make something work? Sounds like a problem others might want to solve, too.
 
Christopher Elkins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, not working yet. I tweeked some code that I had already written (which just overrode the System.out object) to write the following Singleton class.


I then assign the new OutputStream like this:


However, the output still prints to the standard output (console). Any suggestions.
[ October 28, 2004: Message edited by: Christopher Elkins ]
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code works fine in the following test case:


I think your error is that when you do this:


the value of out is the console output stream. If you say out.println(), you print to the console. System.out.println() should work fine (i.e. print to the text area).
 
Christopher Elkins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe. Works like a charm. I'm going to go over here in the corner and bang my head against the wall a few more times now...
think Chris, think...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!