10

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.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Mad
  • 111
  • 1
  • 1
  • 4

2 Answers2

20

Try this:

yourJTextArea.setLineWrap(true);
yourJTextArea.setWrapStyleWord(true);
raffian
  • 31,267
  • 26
  • 103
  • 174
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
0

You can change the scroll bar policy:

JScrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);

This will disable the horizontal scroll bar

Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170
  • 4
    -1, Why would anyone upvote this answer? The question clearly states the poster has tried using "HORIZONTAL_SCROLLBAR_NEVER" and it doesn't do what the poster wants. – camickr Jul 29 '11 at 21:58
  • There was nothing about HORIZONTAL_SCROLLBAR_NEVER in the original post, if the OP edits his post without comment, that isnt my fault. – Hunter McMillen Jul 29 '11 at 23:22
  • Click on the link to the right of the "edited" label and you will see the original text. – camickr Jul 30 '11 at 01:00
  • My mistake, I swore there wasnt anything there. – Hunter McMillen Jul 30 '11 at 02:15
  • so sorry I think it was a my mistake because i was not highlighted 'HORIZONTAL_SCROLLBAR_NEVER' filed in my original post. I said it but didn't highlighted. sorry for that and thanks for answering. – Mad Jul 30 '11 at 03:05
  • @Mad, it is not your fault. The highlighting is nice but not necessary. We need to take the time to fully read the question. What is important is that you accept an answer once you get a solution. – camickr Jul 30 '11 at 03:32