imageicon problem  
Author Message
Tom Wouters





PostPosted: 2003-11-1 22:10:00 Top

java-programmer, imageicon problem 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





PostPosted: 2003-11-1 22:39:00 Top

java-programmer >> imageicon problem "Tom Wouters" <email***@***.com> wrote in message
news:a9Pob.118457$email***@***.com...
> 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



 
Tom Wouters





PostPosted: 2003-11-1 22:50:00 Top

java-programmer >> imageicon problem 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


"Andrew Thompson" <email***@***.com> schreef in bericht
news:qAPob.174074$email***@***.com...
> "Tom Wouters" <email***@***.com> wrote in message
> news:a9Pob.118457$email***@***.com...
> > 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/
>
>
>


 
 
Andrew Thompson





PostPosted: 2003-11-1 23:16:00 Top

java-programmer >> imageicon problem "Tom Wouters" <email***@***.com> wrote in message
news:BKPob.118520$email***@***.com...
> 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.