Swing: Change icon

Is it possible to change the icon that appears at the top-left corner of the title bar in any Swing window? By default, it is the java logo.

If yes, please let me know how. Thanks!
dshrenikAsked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:
Yes, i tried, and it acuatlly worked for me like that:
 public MyFrame(){
        super("My Frame");
        Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
           this.setIconImage(icon);
....
   

Open in new window

0
 
for_yanCommented:
check here:
http://www.java-forums.org/awt-swing/5373-how-change-window-icon.html

    In the Netbeans properties window for your form, try iconImage. Otherwise, try:
    Java Code:
    1
    2
          
    Image icon = Toolkit.getDefaultToolkit().getImage([COLOR=#0066ff]"icon.gif"[/COLOR]);
    frame.setIconImage(icon);

0
 
dshrenikAuthor Commented:
The above code is in the constructor of my class that extends JFrame?
0
 
for_yanCommented:
Yes, exactly
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.