-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoundedBorder.java
41 lines (33 loc) · 1.11 KB
/
RoundedBorder.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
33
34
35
36
37
38
39
40
41
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import javax.swing.border.AbstractBorder;
public class RoundedBorder extends AbstractBorder {
private final int radius;
public RoundedBorder(int radius) {
this.radius = radius;
}
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.setColor(c.getBackground());
g.fillRoundRect(x, y, width, height, radius, radius);
}
@Override
public Insets getBorderInsets(Component c) {
return new Insets(this.radius, this.radius, this.radius, this.radius);
}
@Override
public Insets getBorderInsets(Component c, Insets insets) {
insets.left = insets.top = insets.right = insets.bottom = this.radius;
return insets;
}
@Override
public boolean isBorderOpaque() {
return true;
}
public Shape getBorderShape(int x, int y, int width, int height) {
return new RoundRectangle2D.Double(x, y, width - 1, height - 1, radius, radius);
}
}