Carlo
Carlo

Reputation: 1167

How to wrap text in a JTextArea

I have a JTextArea in Java. When I place a large amount of text in it, the text area provides horizontal scrolling.

How can I make my text area wrap instead?

Upvotes: 38

Views: 89995

Answers (6)

Code on the Rocks
Code on the Rocks

Reputation: 17566

In the IntelliJ GUI Designer, you can just check the "lineWrap" box to get the wrapping functionality: enter image description here

Upvotes: 0

Jed
Jed

Reputation: 1

you would need to use this to wrap text with multiple words.

JTextArea.setWrapStyleWord(true);

Upvotes: 0

Kym NT
Kym NT

Reputation: 790

In a Swing GUI Designer Like Netbeans IDE,

you could just 'check' the lineWrap in jTextArea property window.

if property window is hidden:

Goto WINDOW -> IDE TOOLS -> Properties

or press

CTRL + SHIFT + 7

In Swing GUI

add the line

jTextArea.setLineWrap(true);

Upvotes: 3

sathya
sathya

Reputation: 1424

Try This :

jTextArea.setLineWrap(true);

Upvotes: 18

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

Look at the API for the methods available to JTextArea, in particular setWrapStyleWord and setLineWrap.

Upvotes: 32

Robin
Robin

Reputation: 36601

Use the JTextArea#setLineWrap method. This is also illustrated in the Swing JTextArea tutorial

Upvotes: 80

Related Questions