-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquareButton.java
More file actions
27 lines (22 loc) · 783 Bytes
/
SquareButton.java
File metadata and controls
27 lines (22 loc) · 783 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
import javax.swing.*;
import java.awt.*;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.basic.BasicButtonUI;
public class SquareButton extends JButton {
private static final Color BACKGROUND_COLOR = new Color(64, 64, 64);
public static final int BUTTON_SIZE = 64;
public SquareButton(String text) {
super(text);
setFocusPainted(true);
setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
setBackground(BACKGROUND_COLOR);
setBorder(new EmptyBorder(0, 0, 0, 0));
setUI(new BasicButtonUI());
}
@Override
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
int size = Math.max(d.width, d.height);
return new Dimension(size, size);
}
}