简体   繁体   English

在JTextArea中停止水平滚动

[英]stop horizontal scrolling in JTextArea

I want to add a JTextArea to an application. 我想将JTextArea添加到应用程序。 Normally that textarea contains large content and both horizontal and vertical ScrollBars appear when running that application. 通常,该文本区域包含大量内容,并且在运行该应用程序时会同时出现水平和垂直ScrollBars 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). 我发现可以通过HORIZONTAL_SCROLLBAR_NEVER字段来实现,但是它不会显示完整的内容(它不会水平包装,也不会将内容移动到下一行)。 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 这将禁用水平滚动条

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM