-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRoundedBorder.java
More file actions
32 lines (27 loc) · 1.1 KB
/
Copy pathRoundedBorder.java
File metadata and controls
32 lines (27 loc) · 1.1 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
import java.awt.*;
import javax.swing.border.AbstractBorder;
public class RoundedBorder extends AbstractBorder {
private 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) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(c.getForeground());
g2d.drawRoundRect(x, y, width - 1, height - 1, radius, radius);
g2d.dispose();
}
@Override
public Insets getBorderInsets(Component c) {
// retorna um espaçamento igual em todos os lados, baseado no raio da borda
return new Insets(radius + 1, radius + 1, radius + 1, radius + 1);
}
@Override
public Insets getBorderInsets(Component c, Insets insets) {
// ajusta o objeto insets recebido, deixando todos os lados com o mesmo valor (raio + 1)
insets.left = insets.right = insets.top = insets.bottom = radius + 1;
return insets;
}
}