kerhoswing
Class TextAreaWriter
java.lang.Object
java.io.Writer
kerhoswing.TextAreaWriter
- All Implemented Interfaces:
- Closeable, Flushable, Appendable
public final class TextAreaWriter
- extends Writer
Simple way to "print" to a JTextArea; just say
PrintWriter out = new PrintWriter(new TextAreaWriter(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 |
TextAreaWriter
public TextAreaWriter(JTextArea textArea)
- Parameters:
textArea
- area where to write- Example:
#import java.io.*;
#import javax.swing.*;
JTextArea text = new JTextArea();
PrintWriter tw = new PrintWriter(new TextAreaWriter(text));
tw.print("Hello");
tw.print(" ");
tw.print("world!");
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
- Specified by:
flush
in class Writer
close
public void close()
- Specified by:
close
in interface Closeable
- Specified by:
close
in class Writer
write
public void write(char[] cbuf,
int off,
int len)
throws IOException
- Specified by:
write
in class Writer
- Throws:
IOException
getTextPrintWriter
public static PrintWriter getTextPrintWriter(JTextArea textArea)
- Factory method for creating a PrintWriter to print to selected TextArea
- Parameters:
textArea
- area where to print
- Returns:
- created PrintWriter ready to print to TextArea
- Example:
#import java.io.*;
#import javax.swing.*;
JTextArea text = new JTextArea();
PrintWriter tw = TextAreaWriter.getTextPrintWriter(text);
tw.print("Hyvää");
tw.print(" ");
tw.print("päivää!");
text.getText() === "Hyvää päivää!";