-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRoundedCornerButton.java
More file actions
40 lines (35 loc) · 1.14 KB
/
Copy pathRoundedCornerButton.java
File metadata and controls
40 lines (35 loc) · 1.14 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
import javax.swing.*;
import java.awt.*;
public class RoundedCornerButton extends JButton {
public RoundedCornerButton(String text) {
super(text);
setupButton();
}
public RoundedCornerButton(Icon icon) {
super(icon);
setupButton();
}
public RoundedCornerButton() {
setupButton();
}
private void setupButton() {
setOpaque(false);
setContentAreaFilled(false);
setBorderPainted(false);
setFocusPainted(false);
setForeground(Color.BLACK); // Set text color to white
setFont(new Font("Tahoma", Font.PLAIN, 14)); // Set font for the button text
}
@Override
protected void paintComponent(Graphics g) {
if (getModel().isPressed()) {
g.setColor(new Color(240, 240, 240));
} else if (getModel().isRollover()) {
g.setColor(new Color(220, 220, 220));
} else {
g.setColor(new Color(0xFFFFFF)); // Set the background color for the button
}
g.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15);
super.paintComponent(g);
}
}