Java Swing:JPanel添加边框

一、JPanel添加不同边框的效果图如下所示

 

二、 不同边框样式的代码实现

 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)  

 

posted @ 2018-08-30 08:56  一只敲码的猫  阅读(18382)  评论(0编辑  收藏  举报