Loading a .GIF or .JPG image as the ICON in the java Jframe window?
-
Ok, I'm about searched out. I keep finding the same results in searching, but usually come back with the same code, which isn't working for me. Basically, I'm trying to get rid of the ugly java coffee cup icon, and replace it with an icon of my own. I have a package name of something like com.ex.example1 that contains the source code below. focused.gif exists in that same package, as well as the src directory. When I do the code below, it still shows the java coffee cup icon. I'm sure I'm just doing something wrong, or maybe I'm not putting the path in the getImage statement correctly? Can anyone shed some light on this? Thanks! package com.ex.example1; import java.awt.Image; import java.awt.Toolkit; import javax.swing.JFrame; public class FrameIcon { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(400,400); Image icon = Toolkit.getDefaultToolkit() .getImage("focused.gif"); frame.setIconImage(icon); frame.setVisible(true); } }
-
Answer:
this should work. are you sure the image is in the same directory where you are running your program from? otherwise you have to use the relative path when opening the image. afaik you get no exception when you try to use Toolkit.getImage with a non existent file, all you can do is check if width/hight returns -1.
Darren at Yahoo! Answers Visit the source
Related Q & A:
- How to animate a gif for a very simple loading screen?Best solution by pcmag.com
- How do I make a picture of me as my yahoo icon?Best solution by Yahoo! Answers
- How do I send a gif?Best solution by Yahoo! Answers
- Where can I find a GIF?Best solution by giphy.com
- How does a gif on msn work?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.