I have a javaFX Application that will only load from a JAR however I wanted to change the icon in the mac dock. I have managed to working it out on windows. I am using Netbeans IDE, and would prefer to not add the additional apple JAR Extension file. It is because of this I’m not sure if it is possible.
So far I haven't seen a way to do this with JavaFX but there is a way to do it with Apple-specific Java APIs:
public static void main(String[] args) {
try {
URL iconURL = Main.class.getResource("ui/resources/[email protected]");
Image image = new ImageIcon(iconURL).getImage();
com.apple.eawt.Application.getApplication().setDockIconImage(image);
} catch (Exception e) {
// Won't work on Windows or Linux.
}
launch(args);
}
This works at least with Oracle Java 1.7.0_40 and 1.8.0_25.
The downside is that when you start the JAR, you'll see the Java logo in the dock for a short time which then changes to your icon. This is a technical limitation and can only be worked around by creating a real, native OS X bundle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With