- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to set JTextArea to wrap by word in Java
To set JTextAream to wrap by word, you need to use the setWrapStyleWord(). Let’s say we have created a new JTextArea and set demo text −
JTextArea textArea = new JTextArea("This is a text displayed for our example. More content is added in it now. More content is added in it now. We will now wrap this text!!!!!!!!!!!!!!!!!!!");
Now, wrap by word and set it TRUE −
textArea.setWrapStyleWord(true)
The following is an example to set JTextArea to wrap by word −
Example
package my; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo { SwingDemo() { JFrame frame = new JFrame("Demo"); JTextArea textArea = new JTextArea("This is a text displayed for our example. More content is added in it now. More content is added in it now. We will now wrap this text!!!!!!!!!!!!!!!!!!!"); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); frame.add(textArea); frame.setSize(550,300); frame.setLayout(new GridLayout(2, 2)); frame.setVisible(true); } public static void main(String args[]) { new SwingDemo (); } }
Output
- Related Articles
- How can we implement line wrap and word wrap text inside a JTextArea in Java?
- Java Program to display the contents in JTextArea
- Java Program to paste clipboard text to JTextArea
- Java Program to replace the first 10 characters in JTextArea
- Java Program to set title position in Java
- How can we set the orientation of a JTextArea from right to left in Java?
- Java Program to wrap a Primitive DataType in a Wrapper Object
- Java Program to wrap text in a JTextPane and show Scrollbar
- How can I append text to JTextArea in Java?
- Java program to reverse each word in a sentence
- How can we implement the word wrap JTableHeader of a JTable in Java?
- Word Wrap Problem
- How to word-wrap text in Tkinter Text?
- Java regex program to add space between a number and word in Java.
- Program to convert Array to Set in Java

Advertisements