Normand Briere
2019-11-17 cb37a129d1adb403019c96e798e86e2da9667f15
cButton.java
....@@ -1,5 +1,8 @@
11 public class cButton extends javax.swing.JButton
22 {
3
+ String iconname;
4
+ boolean fit;
5
+
36 cButton(String name)
47 {
58 super(name);
....@@ -22,11 +25,20 @@
2225 }
2326 }
2427
25
- cButton(javax.swing.ImageIcon icon, boolean border)
28
+ cButton(//javax.swing.ImageIcon icon,
29
+ String iconname,
30
+ boolean border, boolean fit)
2631 {
27
- super(icon);
32
+ //super(icon);
33
+ this.iconname = iconname;
34
+ this.fit = fit;
2835
29
- setMargin(new java.awt.Insets(1, 10, 1, 10)); // ??
36
+ assert(border);
37
+
38
+ //setMargin(new java.awt.Insets(1, 10, 1, 10)); // ??
39
+
40
+// if (icon != null && fit)
41
+// this.image = icon.getImage();
3042
3143 //result = new JButton( icon );
3244 //result.setBorderPainted( false );
....@@ -42,4 +54,37 @@
4254 //setBorder(null); //new javax.swing.border.EmptyBorder(0,0,0,0));
4355 }
4456 }
57
+
58
+ private java.awt.Image image;
59
+
60
+ //@Override
61
+ protected void paintComponent(java.awt.Graphics g)
62
+ {
63
+ if (iconname != null)
64
+ {
65
+ javax.swing.ImageIcon icon = ObjEditor.GetIcon(iconname);
66
+
67
+ if (icon == null)
68
+ setName(iconname);
69
+ else
70
+ {
71
+ if (fit)
72
+ this.image = icon.getImage();
73
+ else
74
+ setIcon(icon);
75
+ }
76
+
77
+ iconname = null;
78
+ }
79
+
80
+ if (image != null)
81
+ {
82
+ //if (getWidth() > image.getWidth(null) + 8)
83
+ {
84
+ g.drawImage(image, 0,0, this.getWidth()-1, this.getHeight()-1, this);
85
+ }
86
+ }
87
+ else
88
+ super.paintComponent(g);
89
+ }
4590 }