I have image icons in the same directory in my project as the source file. From the source file I call button.setIcon("image.png"), or button.setIcon("/image.png") or button.setIcon("full/path/to/image.png") but it does not display my image. My question is: how does Smart Gwt resolve url paths for images? I've looked at the documentation and this is not clear. Can anyone help with this? Thanks.
I use successfully the following procedure to get images with SmartGWT working.
At the same level as the client
package of your GWT module I create a folder named public
. (In Eclipse you cannot create a package named public
because this is not a valid package name. You have to create it explicitly as a folder.) This directory with name public
is treated special by GWT. The GWT compiler copies all the included content to the resulting main module directory. So I usually create a subdirectory images
under public
and put all the images belonging to my GWT module in there.
For example:
com/stuff
client
Main.java
...
public
images
a.png
b.png
mainmodule.gwt.xml
Then right at the beginning of the entry point I tell SmartGWT to look at the images
subdirectory for the images (in this example is mainmodule
the name of my main GWT module):
public void onModuleLoad() {
Page.setAppImgDir("[APP]/mainmodule/images/");
...
}
The [APP]
part of the path is special SmartGWT syntax.
Later I am able to create an IButton like so:
final IButton aBtn = new IButton("A Button");
aBtn.setIcon("a.png");
Sometimes it is necessary to create the URL to an image not for SmartGWT but for plain GWT or plain HTML. For these cases you can create the URL with
final String bUrl = GWT.getModuleBaseURL() + "images/b.png";