How to change JFrame icon

Anand picture Anand · Oct 23, 2009 · Viewed 231.6k times · Source

I have a JFrame that displays a Java icon on the title bar (left corner). I want to change that icon to my custom icon. How should I do it?

Answer

BFree picture BFree · Oct 23, 2009

Create a new ImageIcon object like this:

ImageIcon img = new ImageIcon(pathToFileOnDisk);

Then set it to your JFrame with setIconImage():

myFrame.setIconImage(img.getImage());

Also checkout setIconImages() which takes a List instead.