77import java .awt .image .BufferedImage ;
88
99public class GuiUtils {
10- public static void setWmClassName (String className ) throws NoSuchFieldException , IllegalAccessException {
10+ public static void setWmClassName (String className ) {
1111 Toolkit xToolkit = Toolkit .getDefaultToolkit ();
12- java .lang .reflect .Field awtAppClassNameField = xToolkit .getClass ().getDeclaredField ("awtAppClassName" );
13- awtAppClassNameField .setAccessible (true );
14- awtAppClassNameField .set (xToolkit , className );
12+ java .lang .reflect .Field awtAppClassNameField = null ;
13+ try {
14+ awtAppClassNameField = xToolkit .getClass ().getDeclaredField ("awtAppClassName" );
15+ awtAppClassNameField .setAccessible (true );
16+ awtAppClassNameField .set (xToolkit , className );
17+ } catch (Exception e ) {
18+ e .printStackTrace ();
19+ }
1520 }
1621
1722 public static BufferedImage resize (BufferedImage image , int width , int height ) {
@@ -26,4 +31,21 @@ public static ImageIcon resize(Icon icon, int width, int height){
2631 BufferedImage resized = resize (srcImg , width , height );
2732 return new ImageIcon (resized );
2833 }
34+
35+ public static void setLookAndFeel () {
36+ try {
37+ for (UIManager .LookAndFeelInfo info : UIManager .getInstalledLookAndFeels ()) {
38+ if ("Nimbus" .equals (info .getName ())) {
39+ UIManager .setLookAndFeel (info .getClassName ());
40+ break ;
41+ }
42+ }
43+ } catch (Exception e ) {
44+ try {
45+ UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
46+ } catch (Exception e1 ) {
47+ e1 .printStackTrace ();
48+ }
49+ }
50+ }
2951}
0 commit comments