🚸 Set icon for frame
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 27 Nov 2025 11:02:15 +0000 (12:02 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 27 Nov 2025 11:07:41 +0000 (12:07 +0100)
This also sets the icon on the macOS dock, but I have no idea how it looks on
Windows or Linux. If you find out, let me know, will you? Thanks! ðŸ¥°

src/main/java/de/todesbaum/jsite/main/Main.java

index e4d5654..b76f3c5 100644 (file)
 package de.todesbaum.jsite.main;
 
 import java.awt.Component;
+import java.awt.Image;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.text.MessageFormat;
 import java.util.Date;
 import java.util.HashMap;
@@ -199,6 +202,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
                wizard.addWizardListener(this);
                jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
                wizard.setIcon(jSiteIcon);
+               wizard.setIconImage(IconLoader.loadImage("/jsite-icon.png"));
 
                updateChecker = new UpdateChecker(freenetInterface, getVersion());
                updateChecker.addUpdateListener(this);
@@ -775,9 +779,21 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
                        System.out.println("--config-file needs parameter!");
                        return;
                }
+               setIconOnMacOS();
                new Main(configFilename);
        }
 
+       private static void setIconOnMacOS() {
+               try {
+                       Class<?> applicationClass = Class.forName("com.apple.eawt.Application");
+                       Object application = applicationClass.newInstance();
+                       Method setDockIconImageMethod = applicationClass.getDeclaredMethod("setDockIconImage", Image.class);
+                       setDockIconImageMethod.invoke(application, IconLoader.loadImage("/jsite-icon.png"));
+               } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
+                       /* ignore, if any of these don’t work, we’re probably not on macOS. */
+               }
+       }
+
        /**
         * Prints a small syntax help.
         */