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.
Asked
Active
Viewed 1.3k times
10
-
See [here](http://stackoverflow.com/questions/6845382/dynamically-change-the-width-of-jdialog/6845744#6845744) for an example. – Andrew Thompson Jul 30 '11 at 04:27
2 Answers
20
Try this:
yourJTextArea.setLineWrap(true);
yourJTextArea.setWrapStyleWord(true);
-
3You don't need to set the horizontal scroll policy, just the wrapping policy. – camickr Jul 29 '11 at 21:55
-
1
-
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
-
-
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