Created
January 4, 2012 21:59
-
-
Save bchapuis/1562406 to your computer and use it in GitHub Desktop.
Mac osx java application dock icon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works :)