-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuSelectionButton.java
More file actions
37 lines (32 loc) · 1.1 KB
/
Copy pathMenuSelectionButton.java
File metadata and controls
37 lines (32 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
33
34
35
36
37
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class MenuSelectionButton extends JButton{
public MenuSelectionButton(String text){
super(text);
setBorder(new LineBorder(Color.BLACK, 2, false));
setFocusPainted(true);
setVisible(true);
}
@Override
protected void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D)g.create();
Font font = new Font("Gill Sans", Font.PLAIN, 18);
g2.setFont(font);
FontMetrics metrics = g2.getFontMetrics(font);
int hgt = metrics.getHeight();
int adv = metrics.stringWidth(getText());
//g2.setPaint(new GradientPaint(new Point(0, 0),Color.WHITE));
Color color1 = Color.WHITE;
Color color2 = new Color(90,90,90);
GradientPaint gp = new GradientPaint(0, 0, color1, 0, getHeight()*2, color2);
g2.setPaint(gp);
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setPaint(Color.BLACK);
int height = (int)(getHeight()*0.7);
g2.drawString(getText(), getWidth()/2-adv/2, height);
g2.dispose();
//super.paintComponent(g);
}
}