1
2
3
4 package ca.spaz.gui;
5
6 import java.awt.*;
7
8 import javax.swing.JPanel;
9
10 public class TranslucentPanel extends JPanel {
11 double transparency = 1;
12
13 public TranslucentPanel(double transparency) {
14 super();
15 this.transparency = transparency;
16 setOpaque(false);
17 }
18
19 public void paint(Graphics g) {
20 Graphics2D g2d = (Graphics2D)g;
21 g2d.setRenderingHint(
22 RenderingHints.KEY_ANTIALIASING,
23 RenderingHints.VALUE_ANTIALIAS_ON);
24 Composite c = g2d.getComposite();
25 g2d.setComposite(AlphaComposite.getInstance(
26 AlphaComposite.SRC_OVER, (float)transparency));
27 g2d.setColor(getBackground());
28 g2d.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15);
29 g2d.setComposite(c);
30 super.paint(g);
31 }
32
33 }