We will create a custom interface that extends ClientBundle
and call it Icons
, to encapsulate methods that return the icon images as instances of ImageResource
.
public interface Icons extends ClientBundle { ImageResource people(); ImageResource home(); ImageResource orgchart(); }
Our sample Icons
interface extends ClientBundle
and declares three methods, each named with the exact name of an image placed in the same package as the Icons
interface. Having created the interface, we can use it with tabs, buttons, and other GXT components, usually components that implement the IconSupport
interface. However, we will need to convert the ImageResource
object from our Icons
interface to an AbstractImagePrototype
object, which GXT components accept.
Icons ICONS = GWT.create(Icons.class); TabItem homeTab = new TabItem("Home"); homeTab.setIcon(AbstractImagePrototype.create(ICONS.home())); Button btn = new Button("Btn Text"); btn.setIcon(AbstractImagePrototype.create(ICONS.people()));
Note that the image itself can reside in the same package as the interface, or have its path specified with the @Source
annotation.