JTextArea中的自动换行问题

11

我有一个包含长字符串的jTextArea。
假设:

String str = "this is a toooo long string";

现在我想在一个Swing jTextArea中显示这个字符串。但是我的文本区在框架上有限的大小。所以,我无法看到整个字符串。
例如,文本区仅显示:
"this is a t"
是否可能让文本区避免自动引入“\n”隐藏字符? 注:我不想要自动滚动。
谢谢
1个回答

25
JTextArea textArea = new JTextArea(
    "This is an editable JTextArea. " +
    "A text area is a \"plain\" text component, " +
    "which means that although it can display text " +
    "in any font, all of the text is in the same font."
);
textArea.setFont(new Font("Serif", Font.ITALIC, 16));
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);

参考自:http://download.oracle.com/javase/tutorial/uiswing/components/textarea.html


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接