一、JPanel添加不同边框的效果图如下所示
![](https://images2018.cnblogs.com/blog/956352/201808/956352-20180830085138141-1155149285.png)
二、 不同边框样式的代码实现
1 JPanel jpanel = new JPanel();
2
3 jpanel.setBorder(BorderFactory.你需要的样式);
4
5 BorderFactory.createLineBorder(Color.red, 3) //线边框
6
7 BorderFactory.createEtchedBorder() //蚀刻边框
8
9 BorderFactory.createRaisedBevelBorder() //斜面边框(凸)
10
11 BorderFactory.createLoweredBevelBorder() //斜面边框(凹)
12
13 BorderFactory.createTitledBorder("标题") //标题边框左
14
15 BorderFactory.createTitledBorder("标题") //标题边框右
16 setTitleJustification(TitledBorder.RIGHT);
17
18 BorderFactory.createMatteBorder(1, 5, 1, 1, Color.yellow) //花色边框
19
20 b1 = BorderFactory.createLineBorder(Color.blue, 2); //组合边框
21 b2 = BorderFactory.createEtchedBorder();
22 BorderFactory.createCompoundBorder(b1, b2)