Adding the banner

This recipe will create a method that we will use to add a banner in the content panel.

Getting ready

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).

How to do it...

  1. 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;
    }
    
  2. Call the method setTopComponent of the ContentPanel class in the following constructor:
    setTopComponent(getBanner());
    

How it works...

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.

See also

  • The Creating the home page layout class recipe
  • The Adding menus recipe
  • The Creating the left-hand sidebar recipe
  • The Creating the right-hand sidebar recipe
  • The Creating main content panel recipe
  • The Creating the footer recipe
  • The Using the HomePage instance in EntryPoint recipe