-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoolPanel.java
More file actions
41 lines (32 loc) · 1.36 KB
/
CoolPanel.java
File metadata and controls
41 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package Rent_Rover;
import java.awt.*;
import javax.swing.*;
public class CoolPanel extends JPanel {
private int cornerRadius;
public CoolPanel(int radius) {
super();
this.cornerRadius = radius;
setOpaque(false); // allow transparent corners
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int width = getWidth();
int height = getHeight();
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// ---- 1. Draw shadow ----
int shadowGap = 5;
Color shadowColor = new Color(0, 0, 0, 80); // semi-transparent black
g2.setColor(shadowColor);
g2.fillRoundRect(shadowGap, shadowGap, width - shadowGap, height - shadowGap, cornerRadius, cornerRadius);
// ---- 2. Draw background ----
g2.setColor(getBackground()); // use panel background color
g2.fillRoundRect(0, 0, width - shadowGap, height - shadowGap, cornerRadius, cornerRadius);
// ---- 3. Optional border ----
g2.setColor(new Color(0, 0, 0, 60));
g2.setStroke(new BasicStroke(1));
g2.drawRoundRect(0, 0, width - shadowGap, height - shadowGap, cornerRadius, cornerRadius);
g2.dispose();
}
}