Solved

Setting an icon on a java.awt.Frame

Posted on 1997-09-15
12
261 Views
Last Modified: 2008-03-17
I am trying to set the icon for a java.awt.Frame which I am using.  Has anyone done this before and if so, could you provide me with some tips/help.  Thanks.
0
Comment
Question by:Yoda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 

Author Comment

by:Yoda
ID: 1226957
I have been trying to use the setIconImage(image) method with the java.awt.Frame class, but I have not been successful at getting it to work.  Does anyone know how to get this to work correctly?
0
 

Author Comment

by:Yoda
ID: 1226958
I have been trying to use the setIconImage(image) method with the java.awt.Frame class, but I have not been successful at getting it to work.  Has anyone been successful at getting this to work and if so, could you show me what you did?
0
 
LVL 1

Expert Comment

by:quekky
ID: 1226959
try other browser/VM
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Yoda
ID: 1226960
What do you mean?  I do not understand your comment...
0
 
LVL 1

Expert Comment

by:gnawed
ID: 1226961
Show some code or elaborate on the symptoms.
0
 

Author Comment

by:Yoda
ID: 1226962
a = applet;
            theNode = node;
            try
            {
                image = a.getImage(new URL("http://bdssun.bdsinc.com/TreeView.ico"));
                System.out.println("Got image for icon...");
            }
            catch (MalformedURLException e)
            {
            }
            this.setIconImage(image);

This is the code I have in my java.awt.Frame:

I use the setIconImage(image) method and it does not contain the image when I run the frame in my browser.  Everything compiles ok, and the icon is on my server in the correct directory.  It just does not seem to work.
0
 
LVL 1

Accepted Solution

by:
vmanocha earned 50 total points
ID: 1226963
The following program when run using JDK 1.1.3 works and sets the image as specified in the <imagename>. the <imagename> can either be a string pointing to the full path+filename of the image or it can be a URL.

//======
import java.awt.*;

public class J2
{
      public static void main(String args[])
      {
            Frame frm = new Frame("J2");

            try{
                  frm.setIconImage(frm.getToolkit().getImage(<imagename>));
            }
            catch(Exception e)
            {
                  e.printStackTrace();
            }

            frm.reshape(10, 10, 100, 100);
            frm.show();

      }
}
//======
0
 

Author Comment

by:Yoda
ID: 1226964
I tried using that exact same code and when I open up the frame in the browser it still shows the default java icon.  Does it accept .ico or .gif or .jpg?
0
 
LVL 1

Expert Comment

by:vmanocha
ID: 1226965
i used a ".gif" file. btw, what version of JDK are you using and on what paltform ?

0
 

Author Comment

by:Yoda
ID: 1226966
I am using jdk 1.1 on sun solaris
0
 

Author Comment

by:Yoda
ID: 1226967
I am using jdk 1.0 on sun solaris
0
 
LVL 1

Expert Comment

by:vmanocha
ID: 1226968
you are right. it does not seem to work from within a browser. i tried it with Netscape 3.x and MS IE 3.x on Windows NT 4.0. But it does work if you use it in an application using JDK 1.1.3.
Probably it is another one of those browser issues or a bug in JDK 1.0.2 implementation of Java !!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question