Home Java Example Java Awt Setting the Icon for the frame in Java
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Setting the Icon for the frame in Java

Advertisement
In this section, you will learn how to set an icon for the frame in java.

Setting the Icon for the frame in Java

     

Introduction

Here, you will learn how to set the icon of the frame.

This program is the detailed illustration to set the icon to the frame. Toolkit class has been used to get the image and then the image is used to display as frame icon. Toolkit class is used to bind the various components to particular native toolkit implementations. 

getDefaultToolkit():
This method returns the default toolkit.

getImage(url or filename):
This method retrieves the pixels data of the image which can be either in format of .gif, .jpeg or .png. If the security manager installed then the getImage() method first check whether the specified file name has the permission to use and then retrieves the image in pixels format.

Here is the code of the program : 

import java.awt.*;

public class AwtSetIconOfFrame{
public static void main(String[] args){
Frame frame = new Frame("Icon setting for the Awt Frame");
Image icon = Toolkit.getDefaultToolkit().getImage("icon_confused.gif");
Label lbl = new Label("Welcome in Roseindia.net Tutorial.",Label.CENTER);
frame.add(lbl);
frame.setSize(400,400);
frame.setIconImage(icon);
frame.setVisible(true);
  }
}

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 17, 2007

Related Tutorials

Ask Questions?    Discuss: Setting the Icon for the frame in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
joel
March 8, 2012
IT helps

GREAT! THANKS:)
Sumit
July 24, 2012
addActionListener

can we add actionListener to any label.. how can we use HyperLinks in JFrame...
DMCA.com