stop horizontal scrolling in JTextArea
Asked Answered
A

2

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.

Amish answered 29/7, 2011 at 19:55 Comment(1)
See here for an example.Heribertoheringer
M
20

Try this:

yourJTextArea.setLineWrap(true);
yourJTextArea.setWrapStyleWord(true);
Mittiemittimus answered 29/7, 2011 at 20:12 Comment(3)
You don't need to set the horizontal scroll policy, just the wrapping policy.Fanning
Remove explicit horizontal scroll policy change; it is unnecessary.Clarisaclarise
this should be the accepted answer, works fine for me!Estop
L
0

You can change the scroll bar policy:

JScrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);

This will disable the horizontal scroll bar

Leopoldine answered 29/7, 2011 at 20:0 Comment(6)
-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.Fanning
There was nothing about HORIZONTAL_SCROLLBAR_NEVER in the original post, if the OP edits his post without comment, that isnt my fault.Leopoldine
Click on the link to the right of the "edited" label and you will see the original text.Fanning
My mistake, I swore there wasnt anything there.Leopoldine
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.Amish
@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.Fanning

© 2022 - 2024 — McMap. All rights reserved.