Change Java application icon?

Viewed 1742

Does anyone know how to change the default java application app icon? I am using a mac if it makes a difference. Any ideas are good!

4 Answers

Place the icon in your resources folder (src/main/resources for a Maven project with default settings, or alongside the main window class file for an Eclipse project with default settings). (The accepted example uses a hard-coded path in the file system—that is OK in a lab setting, but will break on deployment.)

Assuming theWindow is the main window of your application, do the following:

theWindow.setIconImage(Toolkit.getDefaultToolkit().getImage(
    ClassLoader.getSystemResource("someicon.png")));

If you are subclassing JFrame, you can do this in the constructor (in that case, drop the theWindow. prefix).

Related