Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2003

Tip: Looking for answers? Try searching our database.

imageicon problem

Thread view: 
Tom Wouters - 01 Nov 2003 15:10 GMT
Hello,

I have problem with loading an image from a directory.
I got a folder called images wich is located in my project directory :
c:\MijnJava\Swing_01.
But when i start this application i get a window with a title and in this
window a square that indicates that the picture is not found. Earlier i set
my classpath :  set classpath= .;c:\MijnJava;    this is in windows xp.
I am using Jcreator. The code works fine on my computer in school but not at
home.
I tryed moving the folder images to other directorys but with no luck.
What is the problem with this?
Can anyone help?

thanks
Tom

import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import tomwouters.myswingutils.*;        This is a folder where my packages
are.

public class Afbeelding_01 extends ExitableJFrame{

public Afbeelding_01(String titel){
 super(titel);
 TitledBorder paneelBorder =
  BorderFactory.createTitledBorder("JPanel");

 Container container = getContentPane();
 JPanel paneel = new JPanel();
 paneel.setBorder(paneelBorder);

 JLabel label = new JLabel();
 JLabel label2 = new JLabel();
 ImageIcon afbeelding = new ImageIcon("images/jugg23.gif");
 label.setIcon(afbeelding);
 TitledBorder labelBorder =
     BorderFactory.createTitledBorder("JLabel met jugg23.gif");
 label.setBorder(labelBorder);

 paneel.add(label);
 container.add(paneel);
 pack();
}

   public static void main(String[] args) {
    Afbeelding_01 frameMetAfbeelding = new Afbeelding_01("Afbeelding_01");
    frameMetAfbeelding.setVisible(true);
   }
}
Andrew Thompson - 01 Nov 2003 15:39 GMT
> Hello,

Hi

> I have problem with loading an image from a directory.
> I got a folder called images wich is located in my project directory :
> c:\MijnJava\Swing_01.

java.lang.Class getResource(java.lang.String)
..should fix most 'missing resource' problems.
It returns an URL.

HTH

--
Andrew Thompson
http://www.AThompson.info/
http://www.PhySci.org/
http://www.1point1C.org/
Tom Wouters - 01 Nov 2003 15:50 GMT
Hi,

the image isn't missing . It is there.
So I think that java doesn't look in the correct directory or something.

greets
Tom

> > Hello,
>
[quoted text clipped - 15 lines]
> http://www.PhySci.org/
> http://www.1point1C.org/
Andrew Thompson - 01 Nov 2003 16:16 GMT
> Hi,

Hi Tom,
Please do not 'top-post'.  If you insert
comments where they are relevant, it makes
a conversation easier to follow.

> the image isn't missing . It is there.

Yes, I believe you.

> So I think that java doesn't look in the correct directory or something.

Correct.  That is my understanding also.

That is why I recommended you use the..
java.lang.Class.getResource("myImage.jpg")
..method to locate it for you.

--
Andrew Thompson
http://www.AThompson.info/
http://www.PhySci.org/
http://www.1point1C.org/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.