JTextArea Component in Java GUI
Submitted by donbermoy on Tuesday, May 20, 2014 - 16:25.
This is a tutorial on how to use the JTextArea Component of Java. JTextArea is different from JTextField. Unlike JTextField that will only be used for one line of text, the JTextArea Component can hold more than one line to display text.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of jTextArea.java.
2. Import java.awt.* and javax.swing.* packages because we will going to have the JTextArea component and also the JPanel as the container of this.
3. Instantiate a variable for JTextArea component.
The 5 here means the rows and 18 means the columns of the JTextArea.
4. Create a constructor that is the same with the filename and set textarea's initial text, scrollbar, and border.
Get the content pane, set layout, add to center.
Set window characteristics of the program.
5. In your Main, create a JFrame component that will hold the panel and the textArea and all other components. This will set the size, location, title, and visibility.
Hope this helps! :)
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
- import java.awt.*;
- import javax.swing.*;
- public jTextArea() {
- txtArea.setText("Encode more text to see scrollbars");
- this.setContentPane(content);
- this.pack();
Output:
Here's the full code of this tutorial:
- import java.awt.*;
- import javax.swing.*;
- public jTextArea() {
- txtArea.setText("Encode more text to see scrollbars");
- this.setContentPane(content);
- this.pack();
- }
- txtArea.setTitle("JTextArea Component");
- txtArea.setVisible(true);
- txtArea.setSize(250,140);
- txtArea.setLocation(300,300);
- }
- }
Add new comment
- 82 views