Friday, 14 July 2017

change TitleBar icon in java ~ java help

How to change TitleBar icon in Java AWT and Swing

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

Example to change TitleBar icon in Java AWT

  1. import java.awt.*;     
  2. class IconExample {     
  3. IconExample(){     
  4. Frame f=new Frame();     
  5. Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");    
  6. f.setIconImage(icon);    
  7. f.setLayout(null);     
  8. f.setSize(400,400);     
  9. f.setVisible(true);     
  10. }     
  11. public static void main(String args[]){     
  12. new IconExample();     
  13. }     
  14. }    
Output:
Java How to change titlebar 1


Example to change TitleBar icon in Java Swing

  1. import javax.swing.*;  
  2. import java.awt.*;  
  3. class IconExample {   
  4. IconExample(){   
  5. JFrame f=new JFrame();   
  6. Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");  
  7. f.setIconImage(icon);  
  8. f.setLayout(null);   
  9. f.setSize(200,200);   
  10. f.setVisible(true);   
  11. }   
  12. public static void main(String args[]){   
  13. new ToolkitExample();   
  14. }   
  15. }  
Output:
Java How to change titlebar 2

No comments:

Post a Comment