Skip to content

Instantly share code, notes, and snippets.

@bchapuis
Created January 4, 2012 21:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bchapuis/1562406 to your computer and use it in GitHub Desktop.
Save bchapuis/1562406 to your computer and use it in GitHub Desktop.
Mac osx java application dock icon
try {
Class util = Class.forName("com.apple.eawt.Application");
Method getApplication = util.getMethod("getApplication", new Class[0]);
Object application = getApplication.invoke(util);
Class params[] = new Class[1];
params[0] = Image.class;
Method setDockIconImage = util.getMethod("setDockIconImage", params);
URL url = App.class.getClassLoader().getResource("icon.png");
Image image = Toolkit.getDefaultToolkit().getImage(url);
setDockIconImage.invoke(application, image);
} catch (ClassNotFoundException e) {
// log exception
} catch (NoSuchMethodException e) {
// log exception
} catch (InvocationTargetException e) {
// log exception
} catch (IllegalAccessException e) {
// log exception
}
@jarekdo
Copy link

jarekdo commented Oct 17, 2015

It works :)

@vincentmi
Copy link

it works . Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment