मैं इस सरल समाधान पाया:
public class CustomOutputStream extends OutputStream {
private JTextArea textArea;
public CustomOutputStream(JTextArea textArea) {
this.textArea = textArea;
}
@Override
public void write(int b) throws IOException {
// redirects data to the text area
textArea.append(String.valueOf((char)b));
// scrolls the text area to the end of data
textArea.setCaretPosition(textArea.getDocument().getLength());
// keeps the textArea up to date
textArea.update(textArea.getGraphics());
}
}
तो फिर तुम मानकों का पालन के रूप में बदल देते हैं::
JTextArea textArea = new JTextArea(50, 10);
PrintStream printStream = new PrintStream(new CustomOutputStream(textArea));
System.setOut(printStream);
System.setErr(printStream);
सबसे पहले, आप मानक आउटपुट को बदलने के लिए एक वर्ग बनाने के लिए समस्या यह है कि सभी आउटपुट केवल टेक्स्ट क्षेत्र में दिखाए जाएंगे।
नमूना के साथ स्रोत: http://www.codejava.net/java-se/swing/redirect-standard-output-streams-to-jtextarea
यह कमाल है! :) – Roman