JTextArea is a part of java Swing package . It represents a multi line area that displays text. It is used to edit the text .
JTextArea inherits JComponent class. The text in JTextArea can be set to different available fonts and can be appended to new text . A text area can be customized to the need of user .
Constructors of JTextArea are:
- JTextArea() : constructs a new blank text area .
- JTextArea(String s) : constructs a new text area with a given initial text.
- JTextArea(int row, int column) : constructs a new text area with a given number of rows and columns.
- JTextArea(String s, int row, int column) : constructs a new text area with a given number of rows and columns and a given initial text.
Commonly used methods :
- append(String s) : appends the given string to the text of the text area.
- getLineCount() : get number of lines in the text of text area.
- setFont(Font f) : sets the font of text area to the given font.
- setColumns(int c) : sets the number of columns of the text area to given integer.
- setRows(int r) : sets the number of rows of the text area to given integer.
- getColumns() : get the number of columns of text area.
- getRows() : get the number of rows of text area.
1. Program to create a simple JTextArea
2. Program to create a JTextArea and set a initial text and add buttons to change the font of text area.
Note : The following program might mot run in an online compiler please use an offline IDE
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java Swing | Translucent and shaped Window in Java
- Java Swing | ScrollPaneLayout Class
- Java Swing | JPanel with examples
- Java Swing | Internal Frame with examples
- Java Swing | JMenuBar
- Java Swing | JFileChooser
- Java Swing | JTextField
- Java Swing | JProgressBar
- Java Swing | JPasswordField
- Java Swing | JSpinner
- Java Swing | JPopupMenu
- JLabel | Java Swing
- Java Swing | JToolBar
- JRadioButton | Java Swing
- Java Swing | ToolTip
- Java Swing | JSlider
- Java Swing | JSplitPane with Examples
- Java Swing | JComboBox with examples
- Java Swing | Simple Calculator
- Java Swing | JCheckBox with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.