I'm using this code to set the macOS dock icon of my JavaFX app:
try {
// Sets macOS dock icon:
com.apple.eawt.Application.getApplication().setDockIconImage(SwingFXUtils.fromFXImage(appIcon, null));
} catch (Exception e) {
// Doesn’t work on Windows and Linux
}
I can't run the app on Windows because it throws the error "java: package com.apple.eawt does not exist"
How can I catch a "package x does not exist" error or check if it exists at runtime?
You could try to find out what your current OS is beforehand. There are basically two ways. Either System.getProperty("os.name") or SystemUtils.OS_NAME from Apache Commons Lang.
See also: https://www.baeldung.com/java-detect-os
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