Search code examples
javajframeimageicon

How to set up a custom Frame and Task Bar icon of a Java app?


I have a small and simple Java app that when executed opens a JFrame. My "problem" is that by default the app icon displayed in the Task Bar and the icon displayed i the frame header are the default java icon and I would like to change that. So I tried:

JFrame frame = new JFrame("My Frame");
ImageIcon imgIcon = new ImageIcon("C:\\Users\\Simon\\Documents\\GitHub\\IDD_SW5\\src\\icon.ico");
frame.setIconImage(imgIcon.getImage());

But it keeps showing the default java icon.

Extra questions: 1. I know I should be able to use shorter path, but don't know exactly what since nothing is working. 2. Is .ico file suitable for the frame and Task Bar icons? This .ico file is used for the app, when it is done in .exe 3. Will the Task Bar icon be change automatically when the frame icon is?

Thanks.


Solution

  • Take a look at this example

    frame.setIconImage(Toolkit.getDefaultToolkit().getImage("filePath"));
    

    For a good looking Icon use at least a 32*32 picture