Search code examples
gwtgwt2

Ensure that an image is displayed on browser


How to be sure that an image is displayed on browser before further action?

I want to load some images in certain sequence because i want to be sure that an image will be always as background. I write the following code:

// load the view
final IView bgView = new StaticImgView(Constants.BG_CLASS, "Background", bgPath);
this.dPanel.add(bgView);
bgView.addErrorHandler(new ErrorHandler() {

    @Override
    public void onError(ErrorEvent event) {

        GWT.log("No Background-View.");
        loadLogoView();

    }

});
bgView.addLoadHandler(new LoadHandler() {

    @Override
    public void onLoad(LoadEvent event) {

        GWT.log("Background-View loaded.");
        GWT.log("> " + TicketViewer.this.dPanel.getWidgetCount());
        loadLogoView();

    }

});

But the 'Logo' image is not displayed upon the background..(?).

  • bgView extends Image.

  • loadLogoView contains similar code to load another image.

  • Note that the background image is 800x600, while all the other images are smaller 104x100.


Solution

  • Add a LoadHandler to the image (Image.addLoadHandler(LoadHandler)).