我想让 JFrame 边框透明,所以我正在尝试使用我自己的 Border 类来做到这一点......
private class ShadowBorder extends AbstractBorder {
private static final int RADIUS = 30;
@Override
public boolean isBorderOpaque() {
return false;
}
@Override
public Insets getBorderInsets(Component c) {
return new Insets(RADIUS, RADIUS, RADIUS, RADIUS);
}
@Override
public Insets getBorderInsets(Component c, Insets insets) {
insets.top = RADIUS;
insets.left = RADIUS;
insets.bottom = RADIUS;
insets.right = RADIUS;
return insets;
}
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(new Color(0x66000000, true));
g2d.fillRect(0, 0, width - RADIUS, RADIUS);
}
}
但最终边框不透明。边框内也有白色背景,但我不知道为什么(见附件。图片)。有任何想法吗?
谢谢!