kerhoswing
Class TextAreaOutputStream
java.lang.Object
java.io.OutputStream
kerhoswing.TextAreaOutputStream
- All Implemented Interfaces:
- Closeable, Flushable
public final class TextAreaOutputStream
- extends OutputStream
Simple way to "print" to a JTextArea; just say
PrintStream out = new PrintStream(new TextAreaOutputStream(myTextArea));
Then out.println() et all will all appear in the TextArea.
Source: http://javacook.darwinsys.com/new_recipes/14.9betterTextToTextArea.jsp
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TextAreaOutputStream
public TextAreaOutputStream(JTextArea textArea)
- Parameters:
textArea
- area where to write- Example:
#import java.io.*;
#import javax.swing.*;
JTextArea text = new JTextArea();
PrintStream tw = new PrintStream(new TextAreaOutputStream(text));
tw.print("Hello");
tw.print(" ");
tw.print("world!");
tw.flush();
text.getText() === "Hello world!";
text.setText("");
tw.println("Hello");
tw.println("world!");
text.getText() =R= "Hello\\r?\\nworld!\\r?\\n";
flush
public void flush()
- Specified by:
flush
in interface Flushable
- Overrides:
flush
in class OutputStream
close
public void close()
- Specified by:
close
in interface Closeable
- Overrides:
close
in class OutputStream
write
public void write(int b)
throws IOException
- Specified by:
write
in class OutputStream
- Throws:
IOException
write
public void write(byte[] b,
int off,
int len)
throws IOException
- Overrides:
write
in class OutputStream
- Throws:
IOException
getTextPrintStream
public static PrintStream getTextPrintStream(JTextArea textArea)
- Factory method for creating a PrintStream to print to selected TextArea
- Parameters:
textArea
- area where to print
- Returns:
- created PrintStream ready to print to TextArea
- Example:
#import java.io.*;
#import javax.swing.*;
JTextArea text = new JTextArea();
PrintStream tw = TextAreaOutputStream.getTextPrintStream(text);
tw.print("Hyvää"); // skandit toimi
tw.print(" ");
tw.print("päivää!");
text.getText() === "Hyvää päivää!";
text.setText("");
tw.print("ä");
text.getText() === "ä";