How to Change Java Icon in JFrame
In this tutorial, we are going to see how to change java icon in jframe in Java Swing. 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.
The Toolkit class is the abstract super class of each implementation in Abstract Window Toolkit (AWT). Subclasses of Toolkit are used to link various components.
How to Change Java Icon in JFrame
import javax.swing.*; import java.awt.*; class MyIcon { MyIcon() { JFrame frame = new JFrame(); //specify the image that you want to display on the title bar Image icon = Toolkit.getDefaultToolkit().getImage("sound.png"); frame.setIconImage(icon); frame.setLayout(null); frame.setSize(200,200); frame.setVisible(true); } public static void main(String args[]){ new MyIcon(); } }
Output: