
This recipe will create a method that we will use to add a banner in the content panel.
Place the banner image banner.png
at the location \web\resources\images
. You can use your own image or get it from the code sample provided for this book on the Packt Publishing website (www.packtpub.com).
- Create the method
getBanner:
public ContentPanel getBanner() { ContentPanel bannerPanel = new ContentPanel(); bannerPanel.setHeaderVisible(false); bannerPanel.add(new Image("resources/images/banner.png")); Image("resources/images/banner.png")); return bannerPanel; }
- Call the method
setTopComponent
of theContentPanel
class in the following constructor:setTopComponent(getBanner());
The method getBanner()
creates an instance bannerPanel
of type ContentPanel
. The bannerPanel
will just show the image from the location resources/images/banner.png
. That's why, the header is made invisible by invoking setHeaderVisible(false)
. Instance of the com.google.gwt.user.client.ui.Image
class, which represents the banner image, is added in the bannerPanel
.
In the default constructor of the HomePage
class, the method setTopComponent(getBanner())
is called to set the image as the top component of the content panel.