-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoundedPanel.java
32 lines (27 loc) · 1.12 KB
/
RoundedPanel.java
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
import javax.swing.*;
import java.awt.*;
public class RoundedPanel extends JPanel {
private Color backgroundColor;
private int cornerRadius = 15; // Set the corner radius for rounded effect
public RoundedPanel(LayoutManager layout, int radius) {
super(layout);
this.cornerRadius = radius;
}
public RoundedPanel(LayoutManager layout, int radius, Color bgColor) {
super(layout);
this.cornerRadius = radius;
this.backgroundColor = bgColor;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Dimension arcs = new Dimension(cornerRadius, cornerRadius);
int width = getWidth();
int height = getHeight();
Graphics2D graphics = (Graphics2D) g;
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Draw a rounded rectangle with shadow effect
graphics.setColor(backgroundColor != null ? backgroundColor : getBackground());
graphics.fillRoundRect(0, 0, width - 1, height - 1, arcs.width, arcs.height); // Rounded panel
}
}