JPanel中的圆角边框

时间:2013-12-19 14:36:27

标签: java swing jpanel

我使用以下代码在jpanel中创建圆角边框:

class RoundedBorder extends AbstractBorder {  
public Insets getBorderInsets( Component c, Insets insets ) {  
    insets.left = insets.top = insets.right = insets.bottom = 25;  
    return insets;  
}  

public void paintBorder( Component c, Graphics g, int x, int y,  
        int width, int height) {  
    int w = width;  
    int h = height;  

    g.translate(x, y);  
    g.setColor( c.getBackground().darker() );  
    g.drawRoundRect( 0, 0, w-2, h-2, 30, 30 );  
    g.translate(-x, -y);  
}  

public boolean isBorderOpaque() {  
    return true;  
}} 

panel.setBorder(new RoundedBorder());

工作正常,但是当我更改JPanel背景颜色时,JPanel将避免使用背景颜色制作圆角。

如何将圆角边框设为背景色?

0 个答案:

没有答案