Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of

First, a JTextArea is created as one showing 6 lines and 40 positions, containing text.

Can't scroll it without a scrollpane.

Then a JTextField is created containing text, showing 15 positions :

The textfield calls actionPerformed, when the Enter key is typed in it .

We prevent the user from changing the textarea's contents directly .

We'd like the caret in the textfield.

If the Add button is clicked or the Enter key typed in the textfield,...

, we ask the TextField for its text and add it to the textarea.

If the Clear button is clicked, we replace the textarea's text by an empty String.


A textarea comes in very handy when testing : in it you can show what method is being executed, what value a variable has, etc..


A textarea can also function as a crude editor.


As of 1.4 you can define an input mask...

and use it with JFormattedTextField, subclass of JTextField.

Mask-symbols :
Any valid number, #
Any character, to uppercase, U
Any character, to lowercase, L
Any character or number, A
Any character, ?
Anything, *

Input examples.




Add the scrollpane, not the textarea.