【发布时间】:2014-11-05 00:20:27
【问题描述】:
假设我有一个字符串和 JLabel,JLabel 显示在 JFrame 上:
public String content="Hello fellow stack-overflowers, I want to format this output";
public JLabel jL = new JLabel();
执行以下操作:
jL.setText(content);
我得到这个输出:
Hello fellow stack-overflowers, I want to for..
但我真正想要的是文本不要一直超过标签或文本字段的长度,而是每隔 4 个单词左右换行,例如:
Hello fellow stack-overflowers, I want
to format this output
询问是否需要更多信息。
【问题讨论】:
-
您可以在 JLabel 中使用
<html></html>标签。请参阅'Is there a "word wrap" property for JLabel?' 对于 JTextField,我会说改用 JTextArea。
标签: java swing jlabel jtextfield