-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUtil.java
More file actions
56 lines (46 loc) · 1.01 KB
/
GUtil.java
File metadata and controls
56 lines (46 loc) · 1.01 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
import javax.swing.*;
import java.awt.*;
/** @author Gergely Kota
A class to provide some graphical utilities
*/
public class GUtil
{
public static JPanel filler(int n)
{
JPanel filler = new JPanel();
filler.setPreferredSize(new Dimension(n,n));
return filler;
}
public static JPanel filler(int n, Color c)
{
JPanel filler = filler(n);
filler.setBackground(c);
return filler;
}
public static ImageIcon getIcon(String s)
{
Toolkit tk = Toolkit.getDefaultToolkit();
try
{
return new ImageIcon(tk.getImage(s));
}
catch(Exception e) {return null;}
}
public static boolean buttonFix(JButton jb, String s)
{
return buttonFix(jb, jb.getBackground(), s);
}
// assign the Icon from the file called s if it
// can, else sets the background to c
public static boolean buttonFix(JButton jb, Color c, String s)
{
if(s == null || !new java.io.File(s).exists())
{
jb.setBackground(c);
return false;
}
ImageIcon temp = GUtil.getIcon(s);
jb.setIcon(temp);
return true;
}
}