Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Loading SWT Image
Loading SWT Image [message #453872] Wed, 13 April 2005 13:05 Go to next message
Eclipse UserFriend
Originally posted by: flamereaver.yahoo.co.in

Hi all,
Posted this in newbie section too; but got no reply...So here it goes
again!

I'm writing a plug-in, and when I use the setImage function on a Shell
object, with a relative path like...

objShell.setImage(objDisplay,"icons/pic1.gif");

I get a java.io.FileNotFoundException (due to the relative path). It works
properly for absolute paths.

How do I write a function in my plug-in that "accepts just the relative
path of the image and returns an Image object to it". The function should
be like...

import org.eclipse.swt.graphics.Image;
...
public static Image getImageFunction(Display display, String filename){

/*****************************
* return Image, on no error;
* null, otherwise
*****************************
*/
}

Thanks in advance,
Siv

P.S. For what is is worth!
1. All source files are inside a single package inside the 'src' directory
2. The icon files are not. They are in an 'icons' directory, at the same
level as the 'src' directory.
Re: Loading SWT Image [message #453874 is a reply to message #453872] Wed, 13 April 2005 14:27 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Relative to what? The class or the current directory. The form you are
using will expect it to be relative to the current directory, which when
you start Eclipse is the current directory when you started Eclipse.

If you want it relative to a class, you should use instead.

Image i =
ImageDescriptor.createFromURL(getClass().getResource("icons/pic1.gif ")).createImage();
objShell.setImage(i);

Note: You must do an i.dispose() later when the image is no longer
needed, after the shell has disposed or has been set with a new image.

The above assumes the "icons/..." is relative to the class that results
from the getClass() call. If the directory is actually relative to the
classpath (i.e. it is at the root of some folder/jar that is in the
classpath) then you should use getClass().getResource("/icons/pic1.get")
instead. Note the leading "/". This tells it to not append the package
name (as folders) to the name before searching for it.


--
Thanks,
Rich Kulp
Previous Topic:real fullscreen on pocket pc
Next Topic:[REPOST: Re: How to capture image of a composite]
Goto Forum:
  


Current Time: Fri Apr 26 12:18:11 GMT 2024

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

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

Back to the top