Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Editing Desktop Icon

Status
Not open for further replies.

jeremytaffy

Technical User
Sep 6, 2001
75
US
I have a java program written in 1.3, running on AIX5.1. I am trying to alter the appearance of the icon that is displayed on the desktop when I minimize my program. I know that when you type super("program_name") program_name is displayed, with a picture of the java logo. I want to change the picture to a personlized icon. Any suggestions? Thanks in advance.

J
 
Hi jeremytaffy,
I believe you use swing. You can use the
setIconImage(Image image)
method of the java.awt.Frame class, to achieve what you want.
The following is the code snippet I used.
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image1 = Toolkit.getImage("c:\\java\\myIcon.jpg");
setIconImage(image1);
But be careful while selecting the image file. I wasted a lot of time choosing a wrong format. Hope this helps.

Regards,
Rajarajan
 
Where in the code did u put this snippet? My program has tabbed panes, and i think this may be causing difficulty.

Thanks.
j
 
i put in the code, and it gives me the error:

non-static method getImage(java.lang.String) cannot be referenced from a static context
 
You just need to call setImage() on an instance of Frame or JFrame.

i.e don't call setImage() in the 'public static void main(String[] args)' method as its a static method and setImage is not.

The try putting the code above in the constructor of your JFrame or Frame class. RjB.
 
how do you call the setImage on the JFRame? I am not sure what you mean? do you have an example?? Thanks a million.

J
 
Hi jeremytaffy,
As RjB has explained, you'll have to call setImage() on an instance of Frame of JFrame. This means that, in your main() method, instantiate the class that you've inherited from Frame or JFrame. For example if you have a class called HelloWorldGUI extends JFrame, then
HelloWorldGUI hwg = new HelloWorldGUI();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image1 = Toolkit.getImage("c:\\java\\myIcon.jpg");
hwg.setIconImage(image1);
Hope this helps.

Regards,
Rajarajan
 
I did that, but it is still giving me an error:

non-static variable image1 cannot be referenced from a static context

i have tried putting this virtually everywhere in the code and I still get the same error.

any help would be greatly appreciated
j
 
Hi jeremytaffy,
It appears to me that you haven't put my code snippet into your main method. If you do so it should work. BTW, I can help you further, if you post that part of your code here.

Regards,
Rajarajan
 
public static void main(String[] arguments) {
Testgui tg = new Testgui();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image1 = Toolkit.getImage("/home/gui/square.gif");
tg.setIconImage(image1);
}
it still gives me the error even if I remove the static from the main statement.
j
 
Ok, I see it.

Its just a silly compile error. What you have done is tried to call getImage() as a static method of the Toolkit class - which its not.

>Toolkit toolkit = Toolkit.getDefaultToolkit();
error->Image image1 = Toolkit.getImage("/home/gui/square.gif");

What you need to do is use the instance of the Toolkit class to call getImage. i.e (and renaming one of your variables to make things a bit more specific) :

Toolkit tk = Toolkit.getDefaultToolkit();
Image image1 = tk.getImage("/home/gui/square.gif");

That's your 'non-static variable image1 cannot be referenced from a static context' problem.
RjB.
 
That did it. That worked. I appreciate your help. One last q, is there a specific pixel size of a graphic that needs to be used in unix?? i think for windows it is 16x16. is this correct? is this what it is supposed to be for unix? i am using aix 5.1.

thanks so much.

j
 
Sorry jeremytaffy,
That was a silly spelling mistake on my part.
Sorry once again.

Regards,
Rajarajan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top