JTextArea |
JTextArea x = new JTextArea(); or JTextArea x = new JTextArea( #rows, #columns ); |
JTextAreaObjVar.setEditable( false ); |
To make a JTextArea editable (suitable for input ):
JTextAreaObjVar.setEditable( true ); |
JTextAreaObjVar.setText(""); |
To append (= add) some text (e.g.: "ABC") to the JTextArea:
JTextAreaObjVar.append("ABC"); |
To start a new line in the JTextArea:
JTextAreaObjVar.append("\n"); // "\n" is the newline character |
To read the (entire) string stored in the text field :
String s = JTextAreaObjVar.getText( ); |
import java.awt.*; import javax.swing.*; public class TextArea { public static void main(String[] args) { JFrame f = new JFrame("My GUI"); JTextArea x; x = new JTextArea(); // Make a JTextArea f.getContentPane().add(x); // Stick x.setEditable(true); // Output only x.setText(""); // Clear text area x.append("Hello World\n"); x.append("Hello Again\n"); f.setSize(400, 300); f.setVisible(true); } } |