JLabel、JButton等不能用"\n"换行,但它们支持Html的,所以可以用<br>来实现,例如
String s1 = "abc";
String s2 = "def";
JLabel label = new JLabel("<html>" + s1 + "<br>" + s2 + "</html>");
label的显示结果就是:
abc
def
附上一段小程序:
01 |
本文转自
http://blog.sina.com.cn/s/blog_6eef4a86010140or.html, 仅供学习参考