JLabel l1 = new JLabel("I am a teacher");//我想在a 后面换一行显示....在l1中换行
import javax.swing.*;public class Test extends JFrame{ public Test(){ JLabel jl = new JLabel("<html>I am a <br/> teacher</html>"); jl.setBounds(100,100,5,2); this.add(jl); jl.setHorizontalAlignment(JLabel.CENTER); jl.setVerticalAlignment(JLabel.CENTER); this.setBounds(400,400,400,300); this.setVisible(true); } public static void main (String[] args) { new Test(); } }
这样就换行了 自己run下看效果吧
JLabel l1 = new JLabel("I am a\n teacher");看看行吗?
哈哈,网上搜了一下,简单,用HTML 例如: JLabel l1 = new JLabel("<html>I am <br> a teacher</html>");
JLabel l1 = new JLabel("I am a teacher");//我想在a 后面换一行显示....在l1中换行
public Test(){
JLabel jl = new JLabel("<html>I am a <br/> teacher</html>");
jl.setBounds(100,100,5,2);
this.add(jl);
jl.setHorizontalAlignment(JLabel.CENTER);
jl.setVerticalAlignment(JLabel.CENTER);
this.setBounds(400,400,400,300);
this.setVisible(true);
}
public static void main (String[] args) {
new Test();
}
}
例如:
JLabel l1 = new JLabel("<html>I am <br> a teacher</html>");