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 |
0 |
double transparency = 1; |
12 |
|
|
13 |
|
public TranslucentPanel(double transparency) { |
14 |
0 |
super(); |
15 |
0 |
this.transparency = transparency; |
16 |
0 |
setOpaque(false); |
17 |
0 |
} |
18 |
|
|
19 |
|
public void paint(Graphics g) { |
20 |
0 |
Graphics2D g2d = (Graphics2D)g; |
21 |
0 |
g2d.setRenderingHint( |
22 |
|
RenderingHints.KEY_ANTIALIASING, |
23 |
|
RenderingHints.VALUE_ANTIALIAS_ON); |
24 |
0 |
Composite c = g2d.getComposite(); |
25 |
0 |
g2d.setComposite(AlphaComposite.getInstance( |
26 |
|
AlphaComposite.SRC_OVER, (float)transparency)); |
27 |
0 |
g2d.setColor(getBackground()); |
28 |
0 |
g2d.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15); |
29 |
0 |
g2d.setComposite(c); |
30 |
0 |
super.paint(g); |
31 |
0 |
} |
32 |
|
|
33 |
|
} |