ToolBarButton.java
1.45 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
52
53
54
55
56
57
58
59
60
61
62
63
package morfeusz;
import java.awt.Insets;
import java.net.URL;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
@SuppressWarnings("serial")
public class ToolBarButton extends JButton
{
private String iconName;
public ToolBarButton(Action action, String iconName)
{
super(action);
setText(null);
this.iconName = iconName;
initButton();
}
private void initButton()
{
URL url;
Icon icon;
setRolloverEnabled(true);
setRequestFocusEnabled(false);
setMargin(new Insets(0, 0, 0, 0));
putClientProperty("JToolBar.isRollover", Boolean.TRUE);
setBorderPainted(false);
setContentAreaFilled(false);
url = ClassLoader.getSystemClassLoader().getResource(iconName + ".png");
if (url != null) {
icon = new ImageIcon(url);
setIcon(icon);
}
url = ClassLoader.getSystemClassLoader().getResource(iconName + "_disabled.png");
if (url != null) {
icon = new ImageIcon(url);
setDisabledIcon(icon);
}
url = ClassLoader.getSystemClassLoader().getResource(iconName + "_roll_over.png");
if (url != null) {
icon = new ImageIcon(url);
setRolloverIcon(icon);
}
url = ClassLoader.getSystemClassLoader().getResource(iconName + "_pressed.png");
if (url != null) {
icon = new ImageIcon(url);
setPressedIcon(icon);
}
}
public boolean isFocusTraversable()
{
return isRequestFocusEnabled();
}
}