• Post Reply Bookmark Topic Watch Topic
  • New Topic

Input and Output Streams with JTextArea  RSS feed

 
matt eggbeers
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I was wondering if there was a way to 'connect' a Input and output stream to a jtextarea? What I am really trying to do is have a JTextArea behave like the standard in and standard out. Is this possible? If so how?

What kind of Input/Output Stream classes should I use? Know of any tutorials / examples of doing something like this?

Thanks,
Matt
 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by matt eggbeers:
[QB]I was wondering if there was a way to 'connect' a Input and output stream to a jtextarea?


JTextArea (or any JTextComponent) has read() and write() methods.

What I am really trying to do is have a JTextArea behave like the standard in and standard out.


read() calls for a Reader, not an InputStream, but you can convert with InputStreamReader.

write() calls for a Writer, not an OutputStream, but you can convert with OutputStreamWriter.
 
matt eggbeers
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response, what about when using the Text Object in SWT? Is there a way to do it then? The Text object does not have read or write methods.

Thanks,
Matt
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This blog post describes redirecting OutputStreams (specifically System.out) to a SWT Text component.
 
Michael Dunn
Ranch Hand
Posts: 4632
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!