How to wrap text in a JTextArea

2019-01-11 22:07发布

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?

4条回答
做个烂人
2楼-- · 2019-01-11 22:25

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

查看更多
你好瞎i
3楼-- · 2019-01-11 22:31

Try This :

jTextArea.setLineWrap(true);
查看更多
冷血范
4楼-- · 2019-01-11 22:34

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);
查看更多
SAY GOODBYE
5楼-- · 2019-01-11 22:45

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

查看更多
登录 后发表回答