A tour of swing
JTextArea allows editing of multiple lines of text. JTextArea can be used in conjunction with class JScrollPane to achieve scrolling. The underlying JScrollPane can be forced to always or never have either the vertical or horizontal scrollbar.
Constructors:
JTextArea() - Constructs a new TextArea.
JTextArea(Document doc) -
Constructs a new JTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0).
JTextArea(Document doc, String text, int rows, int columns)-
Constructs a new JTextArea with the specified number of rows and columns, and the given model.
JTextArea(int rows, int columns) -
Constructs a new empty TextArea with the specified number of rows and columns.
JTextArea(String text) -
Constructs a new TextArea with the specified text displayed.
JTextArea(String text, int rows, int columns) -
Constructs a new TextArea with the specified text and number of rows and columns.
Source code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JTextAreaDemo extends JFrame implements ActionListener {
JTextField jtfInput;
JTextArea jtAreaOutput;
String newline = "\n";
public JTextAreaDemo() {
createGui();
}
public void createGui() {
jtfInput = new JTextField(20);
jtfInput.addActionListener(this);
jtAreaOutput = new JTextArea(5, 20);
jtAreaOutput.setCaretPosition(jtAreaOutput.getDocument()
.getLength());
jtAreaOutput.setEditable(false);