How to wrap text in a JTextArea

Carlo picture Carlo · Jan 14, 2012 · Viewed 74.9k times · Source

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?

Answer

Robin picture Robin · Jan 14, 2012

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