日期:2014-05-20  浏览次数:20751 次

Java 怎样设置Label 的字体?
- =
如题~(是不是太简单了?)

------解决方案--------------------
试试下面这个应该可以了,刚刚是百度的
Java code


import javax.swing.*;
import java.awt.*;


public class Demo2 extends JFrame {
    private JLabel[] lb=new JLabel[3];


    public Demo2(String title){
        super(title);
        Container c=this.getContentPane();
        c.setLayout(new FlowLayout());

//        JLabel label = new JLabel("<font color='red' size='24'>文字</font>");
        JLabel label = new JLabel("文字");
        Font font=new Font("Monospaced",Font.BOLD,32);//设置字体格式和大小
        label.setForeground(Color.RED);//设置前景色
        label.setFont(font);
        c.add(label);
        this.pack();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    public static void main(String[] args){
           new Demo2("字体颜色实例");
    }

}