Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Redirect System.out.println() to a JTextArea/JTextPane?  RSS feed

 
Minh Nam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, I am wondering to to redirect all output of the System.out.println() to a JTextArea/JTextPane?

Thanks.
 
Philip Thamaravelil
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


static logStdErr(String s){
System.err.println(s);
myTextPane.setText( myTextPane.getText() + s);

}
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you will need to store the old version of System.out (line 1 in my example), or you will never be able to reset it to the default again.
 
Minh Nam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Note that you will need to store the old version of System.out (line 1 in my example), or you will never be able to reset it to the default again.


That's great! Thanks a bunch
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!