随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)
package com;
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;
public class Text extends JFrame {
public Text() {
this.setLayout(null);
JPanel jp = new JPanel();
jp.setBounds(300, 50, 150, 150);
this.add(jp);
//创建红色线性边框
Border boder = BorderFactory.createLineBorder(Color.red);
//创建带标题边框
Border b = BorderFactory.createTitledBorder(boder, "查询员工");
//设置小容器的边框
jp.setBorder(b);
//在小容器里面添加按钮
JButton j= new JButton("确定");
j.setBounds(20, 20, 80, 20);
jp.add(j);
this.setSize(500, 400);
this.setVisible(true);
this.setDefaultCloseOperation(3);
this.setLocationRelativeTo(null);
this.setResizable(false);
}
public static void main(String[] args) {
Text t = new Text();
}
}