Table of contents
1.
Introduction
2.
Example to change TitleBar icon in Java AWT
3.
Example to change TitleBar icon in Java Swing
4.
Frequently Asked Questions
4.1.
Which method is used to change the icon of frame?
4.2.
What is used to get an instance of the image in AWT?
4.3.
Define Toolkit class.
4.4.
What is the use of Subclasses?
4.5.
Which command is used to set the size of TitleBar?
5.
Conclusion
Last Updated: Mar 27, 2024

Change Title Icon in Java Swing

Author Prachi Singh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The setIconImage() method of the Frame class is used to change the icon of Frame or Window. It changes the icon on the left side of the Frame or Window. The Toolkit class is used to get an instance of the Image class in AWT and Swing. Toolkit class is the abstract superclass of every implementation in the Abstract Window Toolkit(AWT). Subclasses of Toolkit are used to bind various components. It inherits the Object class.

Example to change TitleBar icon in Java AWT

import java.awt.*;     
class IconExample {     
IconExample(){     
Frame f=new Frame();     
Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");    
f.setIconImage(icon);    
f.setLayout(null);     
f.setSize(500,500);     
f.setVisible(true);     
}     
public static void main(String args[]){     
new IconExample();     
}     
}
You can also try this code with Online Java Compiler
Run Code

Example to change TitleBar icon in Java Swing

import javax.swing.*;  
import java.awt.*;  
class IconExample {   
IconExample(){   
JFrame f=new JFrame();   
Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");  
f.setIconImage(icon);  
f.setLayout(null);   
f.setSize(600,600);   
f.setVisible(true);   
}   
public static void main(String args[]){   
new ToolkitExample();   
}   
}
You can also try this code with Online Java Compiler
Run Code


Also read swing components in java

Frequently Asked Questions

Which method is used to change the icon of frame?

The setIconImage() method of the Frame class is used to change the icon of Frame or Window.

What is used to get an instance of the image in AWT?

Toolkit Class is used to get an instance of the image in AWT.

Define Toolkit class.

Toolkit class is the abstract superclass of every implementation in the Abstract Window Toolkit(AWT). 

What is the use of Subclasses?

Subclasses of Toolkit are used to bind various components. It inherits the Object class.

Which command is used to set the size of TitleBar?

setSize command is used to set the size of TitleBar.

Conclusion

After reading about Change Title Icon in Java Swing are you not feeling excited to read/explore more articles on Java Swing? Don't worry; Coding Ninjas has you covered.

However, you may want to pursue our premium courses to give your job an advantage over the competition!

With our Coding Ninjas Studio Guided Path, you may learn about Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and more! Check out the mock test series and participate in the contests on Coding Ninjas Studio if you want to put your coding talents to the test! 

Happy studying!!

Live masterclass