stop horizontal scrolling in JTextArea
I want to add a JTextArea开发者_如何学JAVA
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.
Try this:
yourJTextArea.setLineWrap(true);
yourJTextArea.setWrapStyleWord(true);
You can change the scroll bar policy:
JScrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
This will disable the horizontal scroll bar
精彩评论