java 在 JTextArea 中停止水平滚动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6878345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 17:42:56  来源:igfitidea点击:

stop horizontal scrolling in JTextArea

javaswingjscrollpanejtextareajscrollbar

提问by Mad

I want to add a JTextAreato an application. Normally that textarea contains large content and both horizontal and vertical ScrollBarsappear when running that application. I want to remove horizontal scrolling; I have found that it is possible with HORIZONTAL_SCROLLBAR_NEVERfield 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.

我想向JTextArea应用程序添加一个。通常,该 textarea 包含大量内容,并且ScrollBars在运行该应用程序时会出现水平和垂直。我想删除水平滚动;我发现可以使用 HORIZONTAL_SCROLLBAR_NEVER字段,但它没有显示完整的内容(它没有水平包装并将内容移动到下一行)。如何克服这一点。我想停止水平滚动并将内容放在下一行而不滚动一行。

回答by Eng.Fouad

Try this:

试试这个:

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

回答by Hunter McMillen

You can change the scroll bar policy:

您可以更改滚动条策略:

JScrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);

This will disable the horizontal scroll bar

这将禁用水平滚动条