VOOZH about

URL: https://www.geeksforgeeks.org/java/java-swing-jtextarea/

⇱ Java Swing | JTextArea - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Swing | JTextArea

Last Updated : 10 May, 2022

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: 

  1. JTextArea() : constructs a new blank text area .
     
  2. JTextArea(String s) : constructs a new text area with a given initial text.
     
  3. JTextArea(int row, int column) : constructs a new text area with a given number of rows and columns.
     
  4. 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 : 

  1. append(String s) : appends the given string to the text of the text area.
     
  2. getLineCount() : get number of lines in the text of text area.
     
  3. setFont(Font f) : sets the font of text area to the given font. 
     
  4. setColumns(int c) : sets the number of columns of the text area to given integer.
     
  5. setRows(int r) : sets the number of rows of the text area to given integer.
     
  6. getColumns() : get the number of columns of text area.
     
  7. getRows() : get the number of rows of text area.
     


1. Program to create a simple JTextArea 
 

Output: 
 

👁 Image


2. Program to create a JTextArea and set a initial text and add buttons to change the font of text area. 
 

Output : 
 

👁 Image


 

👁 Image


 

👁 Image


Note : The following program might not run in an online compiler please use an offline IDE 
 

Comment