I tried this way, but it didnt changed?
ImageIcon icon = new ImageIcon("C:\\Documents and Settings\\Desktop\\favicon(1).ico"); frame.setIconImage(icon.getImage());
To add icon to a button, use the Icon class, which will allow you to add an image to the button. Icon icon = new ImageIcon("E:\editicon. PNG"); JButton button7 = new JButton(icon);
The method setIconImage() of the JFrame class is used to change the icon of JFrame or JWindow. It changes the icon that is displayed on the left side of the window. The Toolkit class is used to get an instance of the Image class in AWT and Swing.
Better use a .png file; .ico is Windows specific. And better to not use a file, but a class resource (can be packed in the jar of the application).
URL iconURL = getClass().getResource("/some/package/favicon.png"); // iconURL is null when not found ImageIcon icon = new ImageIcon(iconURL); frame.setIconImage(icon.getImage());
Though you might even think of using setIconImages for the icon in several sizes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With