public static void main(String[] args) {
JFrame jf=new JFrame("测试标签Label");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setLocationRelativeTo(null);
jf.setSize(400,400);
JPanel panel=new JPanel(null);
//创建文本标签
JLabel label01=new JLabel();
label01.setText("李乃龙最帅");
label01.setBounds(200,200,100,18);
label01.setFont(new Font("楷体",Font.BOLD,25));
panel.add(label01);
//显示图片
JLabel label02=new JLabel();
//给label添加图标
label02.setIcon(new ImageIcon("src/image/title.png"));
label02.setBounds(200,80,120,120);
panel.add(label02);
//显示文字和图片
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
System.out.println(d);
JLabel label03=new JLabel();
int width = 320;//The application's width
int height = 360;
label03.setForeground(Color.GREEN); //设置字体颜色
label03.setText("吃橘子");
label03.setIcon(new ImageIcon("src/image/title.png"));
label03.setBounds((d.width-width)/2, (d.height-height)/2, width, height);
//水平方向居中
label03.setHorizontalTextPosition(SwingConstants.CENTER);
//垂直方向最底下
label03.setVerticalTextPosition(SwingConstants.BOTTOM);
panel.add(label03);
jf.setContentPane(panel);
jf.setVisible(true);
}
Swing测试标签Label
最新推荐文章于 2023-10-01 16:25:29 发布