Is A Lazy Image Loading Possible?

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

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

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.