Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » ImageDescriptor.createFromFile
ImageDescriptor.createFromFile [message #51491] Wed, 28 May 2003 10:14 Go to next message
Eclipse UserFriend
Originally posted by: gg.decisionsoft.com

I'm trying to load a gif from my icons directory.
The problem I have is that I'm trying to use
ImageDescriptor.createFromFile yet the documentation for the method is
confusing, specifically the location parameter:

location - the class whose resource directory contain the file

How does a Class relate to a resource directory?

Geoff.
Re: ImageDescriptor.createFromFile [message #52154 is a reply to message #51491] Wed, 28 May 2003 16:06 Go to previous messageGo to next message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
Yeah, I too found that kind of confusing when I was first trying to get
Images to work in Eclipse. The phrase seems to mean something like "the
actual directory of the class-file of the class". Here is what we did
that works:

a) put all icons in a directory called "icons" (or whatever) that itself
is directly under our eclipse/workspace/com.foo.ourprojectname directory
(that com.foo.ourprojectname directory is the one that Eclipse wants to
create for your plugin project)

b) refer to every icon via a path (String) of this form
"icons/myGifThatLooksCool.gif"

c) use this code (where the class YourPlugin_Plugin is created by Eclipse
in your
eclipse/workspace/com.foo.ourprojectname/src/com/foo/ourproj ectname
directory):

public static ImageDescriptor getImageDescriptor (final String
fileName) {
final URL installURL =

YourPlugin_Plugin.getDefault().getDescriptor().getInstallURL ();
try {
final URL url = new URL(installURL, fileName);
return ImageDescriptor.createFromURL(url);
}
catch (MalformedURLException mue) {
reportError(
"getImageDescriptor(): couldn't find image: "
+ installURL
+ fileName);
return null;
}
}

HTH,
Paul K

Geoff Gibbs wrote:

> I'm trying to load a gif from my icons directory.
> The problem I have is that I'm trying to use
> ImageDescriptor.createFromFile yet the documentation for the method is
> confusing, specifically the location parameter:
>
> location - the class whose resource directory contain the file
>
> How does a Class relate to a resource directory?
>
> Geoff.
Re: ImageDescriptor.createFromFile [message #52234 is a reply to message #52154] Wed, 28 May 2003 17:54 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.NOSPAM.us.ibm.com

The phrase refers to the way resources should be loaded in Java. It uses
Class.getResourceAsStream(String filename). Look this up in Java and
you'll see how it works. This is for loading resources which are in your
class path (and jars).
Previous Topic:[ANN] Ant Script for install/update Eclipse
Next Topic:[Team] Eclipse spontaneously unable to connect to host
Goto Forum:
  


Current Time: Thu Dec 26 11:00:15 GMT 2024

Powered by FUDForum. Page generated in 0.04293 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top