By Tony Bevis on Thursday, 19 October 2023
Category: Java

Java programming course: 14.4 JTextArea

JTextArea

Whereas JTextField allows the user to enter text on a single line, the JTextArea class allows entry of text in a box consisting of multiple lines, which is useful for entering information such as an address, for example:


Like JTextField, you can supply some default text using a three-argument constructor:

The frame should look as follows:

To handle the possibility of the user typing text which extends beyond the number of rows or columns, it is advisable to nest the JTextArea object within a JScrollPane. The JScrollPane object will monitor the text within the nested component and automatically display horizontal and/or vertical scroll bars if necessary:

Try entering some text on multiple lines and notice the effect:

Next lesson: 14.5 JButton

Related Posts

Leave Comments