-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRollButton.java
More file actions
51 lines (44 loc) · 1.5 KB
/
Copy pathRollButton.java
File metadata and controls
51 lines (44 loc) · 1.5 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
41
42
43
44
45
46
47
48
49
50
51
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
/** @see https://stackoverflow.com/a/14410594/230513 */
public class RollButton {
private static final int N = 64;
private void display() {
JFrame f = new JFrame("RollButton");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel(new GridLayout());
p.setBorder(BorderFactory.createEmptyBorder(N, N, N, N));
p.add(createButton(UIManager.getIcon("ERROR_ICON")));
f.add(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
private JButton createButton(Icon icon) {
JButton b = new JButton();
b.setBorderPainted(false);
b.setText("");
// https://stackoverflow.com/a/14410597/230513
b.setIcon(new ImageIcon(new BufferedImage(icon.getIconWidth(),
icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB)));
b.setRolloverEnabled(true);
b.setRolloverIcon(icon);
return b;
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new RollButton().display();
}
});
}
}