I currently have a program that prints lines of text to the screen in various manners such as \'System.out.println()\' statements and for loops the print all elements in an
An idea:
Create your own PrintStream that outputs everything to this textbox. Then set this new PrintStream to be the standard output stream like that:
System.setOut(myPrintStream());
Check out this blog article, entitled Redirecting System.out and System.err to JTextPane or JTextArea. It describes almost everything you need.
The basic idea is that you create your own specialized output stream. In your implementation of the write()
methods, you call some code to append the new data to your text box. Then, you set this new output stream as your System.out
by calling System.setOut()
or System.setErr()
.
NOTE: that article is missing one thing. You need to start your program in a separate thread.