title: Display a GWT Image in a centered PopupPanel onLoad
body: <p>Using GWT I am displaying an image thumbnail with a ClickHandler that then shows the full image (can be several MB) in a centered PopupPanel. In order to have it centered the image must be loaded before the popup is shown, otherwise the top-left corner of the image is placed in the middle of the screen (the image thinks it is 1px large). This is the code I am using to do this:</p>
  
  <pre><code>    private void showImagePopup() {
          final PopupPanel popupImage = new PopupPanel();
          popupImage.setAutoHideEnabled(true);
          popupImage.setStyleName("popupImage"); /* Make image fill 90% of screen */
  
          final Image image = new Image();
          image.addLoadHandler(new LoadHandler() {
              @Override
              public void onLoad(LoadEvent event) {
                  popupImage.add(image);
                  popupImage.center();
              }
          });
          image.setUrl(attachmentUrl + CFeedPostAttachment.ATTACHMENT_FILE);
          Image.prefetch(attachmentUrl + CFeedPostAttachment.ATTACHMENT_FILE);
      }
  </code></pre>
  
  <p>However, the <code>LoadEvent</code> event is never fired, and thus the image is never shown. How can I overcome this? I want to avoid using <a href="http://code.google.com/p/gwt-image-loader/" rel="nofollow">http://code.google.com/p/gwt-image-loader/</a> because I do not want to add extra libraries if I can avoid it at all. Thanks.</p>