JLabel
package com.company; import javax.swing.*; import java.awt.*; public class Main extends JFrame { public Main(){ setBounds(100,100,200,100); setDefaultCloseOperation(EXIT_ON_CLOSE); Container c=getContentPane(); setVisible(true); JLabel l=new JLabel("这是一个标签"); // l.setText("更改标签内容"); // System.out.println(l.getText()); l.setFont(new Font("微软雅黑",Font.BOLD,15));//更改字体和大小 l.setForeground(Color.red);//更改前景色,跟改字体颜色 c.add(l); } public static void main(String[] args) { // write your code here new Main(); } }