How to wrap text in a JTextArea

a 夏天 提交于 2019-11-27 03:04:46

问题


I have a JTextArea in Java. When I place a large amount of text in it, the text area provides horizontal scrolling.

How can I make my text area wrap instead?


回答1:


Use the JTextArea#setLineWrap method. This is also illustrated in the Swing JTextArea tutorial




回答2:


Look at the API for the methods available to JTextArea, in particular setWrapStyleWord and setLineWrap.




回答3:


Try This :

jTextArea.setLineWrap(true);



回答4:


In a Swing GUI Designer Like Netbeans IDE,

you could just 'check' the lineWrap in jTextArea property window.

if property window is hidden:

Goto WINDOW -> IDE TOOLS -> Properties

or press

CTRL + SHIFT + 7

In Swing GUI

add the line

jTextArea.setLineWrap(true);


来源:https://stackoverflow.com/questions/8858584/how-to-wrap-text-in-a-jtextarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!