Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Setting an Icon for a Frame in Java 
 

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

 

Setting an Icon for a Frame in Java

                         

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

This program helps us to set the icon (image) on the title bar of the frame. When you open frame or window the icon situated on the title bar is seen on the taskbar also. For this purposes, various methods as follows has been used:

frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif"));
Above method sets the icon for the frame or window after getting the image using the Image class method named
getImage().

frame.getDefaultToolkit():
This is the method of the Toolkit class which gets the default toolkit.

Here is the code of program:

import javax.swing.*;
import java.awt.*;

public class SettingIconFrame{
  public static void main(String[] args){
    JFrame frame = new JFrame("Setting an Icon for a frame");
    frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif"));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400,400);
    frame.setVisible(true);
  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c class orm form io method sed format 2d get ip translation return instance transform show for transformation to draw

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

13 comments so far (
post your own) View All Comments Latest 10 Comments:

how to create login screen in swing

Posted by susheela on Monday, 04.6.09 @ 13:49pm | #86538

Well, I had two windows, in my project.... When I apply the above said lines on my first window, it is working... but when i write the same thing in my second window, this thing is not working for me.... Hope you can suggest me something.....

Posted by Gagandeep Bali on Saturday, 12.20.08 @ 11:20am | #82999

I put an image called "icon_confused.gif" in the same location as the class, but no image is ever showing in the frame. Suggestions or explanations?

Posted by John on Friday, 09.26.08 @ 20:39pm | #80727

This tutorial provides an efficient way to learn java.it provides list of chapters incorporated.

Posted by somepallirajesh on Wednesday, 06.11.08 @ 14:29pm | #63008

This tutorial provides an efficient way to learn java.it provides list of chapters incorporated.

Posted by somepallirajesh on Wednesday, 06.11.08 @ 14:16pm | #63007

When i saw this site ,i felt very happy.Because all methos are available with program.

Posted by Govind on Thursday, 08.2.07 @ 14:13pm | #22482

Unable to see the image.

Pls help.

Thanks in advance

Posted by Balu on Wednesday, 03.7.07 @ 12:16pm | #10948

it is very nice site to understand the concepts of java

Posted by dillibabu.s on Tuesday, 02.27.07 @ 13:11pm | #9812

Is it really has to be .gif picture? cause I've tried with .ico and .jpg and it didn't work ;(

Posted by julia on Saturday, 01.13.07 @ 04:36am | #3318

I am a student in my second Java course at the University of Phoenix. I have been desperately trying to find a way to set a custom icon within the construct of JOptionPane.ShowMessageDialog. I have looked on Sun's web site, and I have searched high and low, but find it very difficult to find the information I am looking for.

Normally, an icon of an "i" with a circle appears to the left of the message displayed in an JOptionPane dialog. I simply want to replace that image with another icon that is a GIF file. I know this is theoretically possible, but would love any information you can provide on how to accomplish this goal.

Posted by Robert Hieger on Monday, 01.1.07 @ 11:55am | #2362

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.