简体   繁体   中英

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.

Take a look at this example

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM