Title: RE: Path Files

Use the following construct:

ImageIcon image = new ImageIcon( getClass().getResource( "images/file_close.gif" ) );

This construct will find resources that are in the classpath.

Suppose this code is in a class in a package com.mycompagny.application, then you need to put the image in the directory com/mycompagny/application/images. This is because the getResource() method looks relative to the current package you are in.

Suppose you want to use the same image in a class in the package com.mycompagny.somepackage, but want to keep the image in the same location, then you can refer to it using:

ImageIcon image = new ImageIcon( getClass().getResource( "/com/mycompagny/application/images/file_close.gif" ) );

Notice the slash (/) at the start! By using that the package level you are currently in, is not taken into account. If you would leave out the slash before the com, then image would be searched in the directory com/mycompagny/somepackage/com/mycompagny/application/images

regards,

Wim



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: dinsdag 17 februari 2004 12:39
To: [EMAIL PROTECTED]
Subject: Path Files


In my program I'm using ImageIcon for the buttons and I had this code

Action actClose = new AbstractAction("Close", new
ImageIcon("images/file_close.gif")){...}

This works if I'm in the correct directory, but if I'm not the images are
not found.

What is the correct way to do the previus code?

Thanks
Marcos
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
- - - - - - - - DISCLAIMER - - - - - - - -
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.

Reply via email to