Solved

Setting an icon on a java.awt.Frame

Posted on 1997-09-15
12
259 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
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
print map entry 34 72
iterator/ListIterator approach 17 39
How to execute a Python program and gather return output in Java 2 40
jmss example java 2 23
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

829 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