Reproduced from: http://blog.sina.com.cn/s/blog_6eef4a86010140or.html
JLabel, JButton, etc. cannot be wrapped in "\ n", but they support HTML, so they can be implemented with <br>, such as String S1 = "abc"; String s2 = "Def"; JLabel label = Newjlabel ("Attach a small procedure:
01PackageCom.kaso.Test; 02 03ImportJavax.swing.JFrame; 04ImportJavax.swing.JLabel; 05 06Public classTestframeextendsJFrame { 07PrivateJLabel label =NewJLabel (""); 08 09 PublicTestframe () { 10 This. Add (label); One String s = Fun (); Label.settext ("13} 14 15PrivateString Fun () { StringBuffer SB =NewStringBuffer (); 17 for(inti = 1; I <= 9; i++) { 18 for(intj = 1; J <= I; J + +) { Sb.append (j + "X" + i + "=" + I * j + ""); 20} Sb.append ("<br>"); 22} 23 returnSb.tostring (); 24} 25 26Public StaticvoidMain (string[] args) { Testframe T =NewTestframe (); T.setvisible (true); T.pack (); T.setdefaultcloseoperation (Exit_on_close); 31} 32} |