-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoundedPasswordField.java
More file actions
32 lines (27 loc) · 924 Bytes
/
RoundedPasswordField.java
File metadata and controls
32 lines (27 loc) · 924 Bytes
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 RoundedPasswordField extends JPasswordField {
private Shape shape;
public RoundedPasswordField(int size) {
super(size);
setOpaque(false);
}
@Override
protected void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRoundRect(0, 0, getWidth()-1, getHeight()-1, 30, 30);
super.paintComponent(g);
}
@Override
protected void paintBorder(Graphics g) {
g.setColor(getForeground());
g.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 30, 30);
}
@Override
public boolean contains(int x, int y) {
if (shape == null || !shape.getBounds().equals(getBounds())) {
shape = new java.awt.geom.RoundRectangle2D.Float(0, 0, getWidth()-1, getHeight()-1, 30, 30);
}
return shape.contains(x, y);
}
}