简体   繁体   English

如何在 JTextArea 中换行

[英]How to wrap text in a JTextArea

I have a JTextArea in Java.我在 Java 中有一个 JTextArea。 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?我怎样才能让我的文本区域换行?

Use the JTextArea#setLineWrap method.使用JTextArea#setLineWrap方法。 This is also illustrated in the Swing JTextArea tutorial Swing JTextArea教程中也说明了这一点

查看 JTextArea 可用方法的 API,特别是setWrapStyleWordsetLineWrap

尝试这个 :

jTextArea.setLineWrap(true);

In a Swing GUI Designer Like Netbeans IDE,在像 Netbeans IDE 这样的 Swing GUI 设计器中,

you could just 'check' the lineWrap in jTextArea property window.您可以在 jTextArea 属性窗口中“检查” lineWrap。

if property window is hidden:如果属性窗口被隐藏:

Goto WINDOW -> IDE TOOLS -> Properties

or press或按

CTRL + SHIFT + 7

In Swing GUI在 Swing GUI 中

add the line添加行

jTextArea.setLineWrap(true);

您将需要使用它来包装带有多个单词的文本。

JTextArea.setWrapStyleWord(true);

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

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