使用setFont(Font t)设置全部文字样式、大小
lab.setFont(new Font("宋体", 0, 25));
第一个参数代表字体
中间的0代表不加粗,改成1代表加粗
最后的代表文字大小
使用setForeground(Color c)设置全部文字颜色
label.setForeground(Color.red);
使用html语法换行、设置部分文字颜色:
"<html>this line<br><font color='red'>add a new line</font></html>"
其中<br>
为换行。
效果如下: