stop horizontal scrolling in JTextArea

Mad picture Mad · Jul 29, 2011 · Viewed 12.3k times · Source

I want to add a JTextArea to an application. Normally that textarea contains large content and both horizontal and vertical ScrollBars appear when running that application. I want to remove horizontal scrolling; I have found that it is possible with HORIZONTAL_SCROLLBAR_NEVER field but then it does not show the complete contents (it doesn't wrapped horizontally and move content to next row). how to overcome this. I want to stop horizontal scrolling and put contents in next row without scrolling it on a row.

Answer

Eng.Fouad picture Eng.Fouad · Jul 29, 2011

Try this:

yourJTextArea.setLineWrap(true);
yourJTextArea.setWrapStyleWord(true);