Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Simple question: image on button gives red square
Simple question: image on button gives red square [message #460465] Mon, 29 August 2005 10:49 Go to next message
Koen van Dijken is currently offline Koen van DijkenFriend
Messages: 67
Registered: July 2009
Member
I have a Button on which I try to put an image

static {
ImageRegistry reg = JFaceResources.getImageRegistry();
reg.put(CELL_EDITOR_IMG_DOTS_BUTTON, ImageDescriptor.createFromFile(
DialogCellEditor.class,
"images/dots_button.gif"));//$NON-NLS-1$
}


and later when the Button is created:

Button button = new Button(parent, SWT.DOWN);
button.setImage(JFaceResources.getImageRegistry().get(
CELL_EDITOR_IMG_DOTS_BUTTON));

I get a small red square on the button instead of the image. The image is
loaded succesfully in the ImageRegistry. The button is large enough to
accomodate the image.

What am I doing wrong?

Koen
Re: Simple question: image on button gives red square [message #460469 is a reply to message #460465] Mon, 29 August 2005 15:37 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

It means it can't find the image on disk. The red square is the "missing
image" image that is returned when it can't find the image.

In your example below:

- First I make the assumption that DialogCellEditor() is your
celleditor, and for this example let's call it: com.mine.DialogCellEditor.

- So for this example to work, the images directory must be in your
classpath and it must be under the com/mine directory. That is because
the createFromFile(class, path) uses class.getResourceAsStream(path) to
find the image. Since you had no leading '/' on the path, it will
automatically take the package name of the class (i.e. "com.mine") and
change the '.' to '/' and prefix that to the path. So in your case it
will look in the classpath for "/com/mine/images/dots_button.gif"

Koen van Dijken wrote:
> I have a Button on which I try to put an image
>
> static {
> ImageRegistry reg = JFaceResources.getImageRegistry();
> reg.put(CELL_EDITOR_IMG_DOTS_BUTTON, ImageDescriptor.createFromFile(
> DialogCellEditor.class,
> "images/dots_button.gif"));//$NON-NLS-1$
> }
>
>
> and later when the Button is created:
>
> Button button = new Button(parent, SWT.DOWN);
> button.setImage(JFaceResources.getImageRegistry().get(
> CELL_EDITOR_IMG_DOTS_BUTTON));
>
> I get a small red square on the button instead of the image. The image is
> loaded succesfully in the ImageRegistry. The button is large enough to
> accomodate the image.
>
> What am I doing wrong?
>
> Koen
>
>
>

--
Thanks,
Rich Kulp
Previous Topic:GridData exclude problem
Next Topic:Multiple Display instances questions...
Goto Forum:
  


Current Time: Tue Sep 24 04:39:00 GMT 2024

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

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

Back to the top