File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Problems dispaying icon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problems dispaying icon" Watch "Problems dispaying icon" New topic

Problems dispaying icon

Dean Reedy
Ranch Hand

Joined: Sep 10, 2001
Posts: 89
I have a package called divelog, with a subdirectory of images, with a file diveflag.gif
I am trying to load a image into a label by:
jl = new JLabel("Java(TM) Technology Dive Log", new ImageIcon("images/diveflag.gif"), JLabel.CENTER);

When I run the application no image appears. Any ideas?
Dean Reedy
Ranch Hand

Joined: Sep 10, 2001
Posts: 89
I added the full path from where the JAVA machine was running and it worked. I thought you only had to path it from where the class files exists. Does anyoine know the rules?
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

I think Java uses the CLASSPATH to search for images also... is the directory directly above /images on the classpath?

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Jaunty John

Joined: Jul 14, 2002
Posts: 21
The '/images' subdirectory must be a subdirectory of the directory where the code is located that calls for the image. For instance, if the code for is located at 'C:\MyApps\divelog', then the '/images' sub must be located at 'C:\MyApps\divelog\images'. The CLASSPATH knows where to find it because it starts at the current directory, and your code gives it a relative path to the *.gif file, 'new ImageIcon("images/diveflag.gif"), JLabel.CENTER);', (the part in the double quotes).

(((o o)))<br />""--^--"" Entropy is Increasing...
I agree. Here's the link:
subject: Problems dispaying icon
It's not a secret anymore!