Skip to main content
gamedev.net
🔒 Locked

Java Icons

Started by Fuji Mar 27, 2010 at 1:49 PM 8 replies 1.1k views
Original Post
Fuji
Fuji
I have been trying to find a way to modify the icons for the top of the window and the JAR file my project creates. All I've found so far is ImageIcon, and displaying images to the screen isn't my aim at the moment. Is there a class for this? Is it even possible? Thanks in advance.
C++: Where your friends have access to your private members
beckyj
beckyj
I know you can't change the file icon for .jar files, you'd have to make it an .exe but I know you can change the title bar image with http://java.sun.com/j2se/1.3/docs/api/java/awt/Frame.html#setIconImage%28java.awt.Image%29
Fuji
Fuji
Ok, I got the image to work as the icon while it runs in NetBeans, but when I run the jar alone, the image doesn't show up.
C++: Where your friends have access to your private members
Momoko_Fan
Momoko_Fan
For creating an exe file with your own icon you can use Launch4J.
Fuji
Fuji
The icon I speak of is the small one at the top of the window. I don't care too much about an exe icon as this since I've already gotten it to display. I'm just unsure as to why the image only displays while I run it from NetBeans.
C++: Where your friends have access to your private members
Stani R
Stani R
Quote:
Original post by Fuji
The icon I speak of is the small one at the top of the window. I don't care too much about an exe icon as this since I've already gotten it to display. I'm just unsure as to why the image only displays while I run it from NetBeans.


Post the loading code. Maybe there is a problem loading the icon. It is included in your jar? Are you using getResourceAsStream() or similar method?
Fuji
Fuji
image = new ImageIcon("vclogo.png").getImage();
window.setIconImage(image);

These are the two lines involved with the image. I have the image in the project folder.
C++: Where your friends have access to your private members
Stani R
Stani R
It would be better to include the image as part of the jar and load it with the classloader, but this works. Do you have a Main-Class entry in your jar manifest? Is the jar in the same directory as the image?
beckyj
beckyj
I had this problem in eclipse, what you have to do is add the images to the build path, or simply place them in the same folder as the source code, so then they will actually be included in the jar. Then you need to load the image like so:

URL imageURL = getClass().getResource("icon.gif");icon = new ImageIcon(imageURL);
Fuji
Fuji
Thanks, that solved my issue
C++: Where your friends have access to your private members

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.