我使用以下代码在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将避免使用背景颜色制作圆角。
如何将圆角边框设为背景色?