Gwt popup is not centered

I use the gwt popup to display some messages, but it does not appear in the center of the display event if I call popup.center (). In fact, it is not centered only for the first time, if I close it and open it again, everything will be fine, but not the first time. How to fix it?

GWT.runAsync(new RunAsyncCallback() { @Override public void onSuccess() { Image fullImage = new Image(optionImageName); fullImage.setAltText("Loading image ..."); imagePopup.setWidget(fullImage); imagePopup.center(); } }); 

I found this question at http://www.devcomments.com/gwt-Popup-is-not-centered-at107182.htm , and today I also had this problem. I found the answer and I will post it here for future reference.

+4
source share
3 answers

I found that the problem is that the image does not load when you center the popup. This happens for the first time only because the second time the image is somehow cashed by the browser.

The solution is to center it also on the onLoad event.

 GWT.runAsync(new RunAsyncCallback() { @Override public void onSuccess() { Image fullImage = new Image(optionImageName); fullImage.setAltText("Loading image ..."); fullImage.addLoadHandler(new LoadHandler() { @Override public void onLoad(LoadEvent event) { imagePopup.center(); } }); imagePopup.setWidget(fullImage); imagePopup.center(); } }); 
+2
source

I also had this problem. The reason you need to call the center twice is because the pop-up container is actually removed from the DOM when the pop-up is β€œhidden”. This is problematic because your popup should now β€œshow” the contents of the popup before you can verify that the image is loaded.

The problem with the recommended implementation is that the first call to the center () function will fail if the image is not cached. A second call to the center will fix it. In the browser, this causes the pop-up dialog box to shift (which looks pretty bad).

I would recommend the following: 1. Place the pending counter on the same display and show it first. 2. One called loadHandler, displays the image, hides the counter and regenerator.

+1
source
  public void onClick(ClickEvent event) { // TODO Auto-generated method stub final ADPopup popup = new ADPopup(); popup.setHeight("300px"); popup.setWidth("500px"); popup.setPopupPositionAndShow(new PopupPanel.PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { // TODO Auto-generated method stub int left = (Window.getClientWidth() - offsetWidth) / 3; int top = (Window.getClientHeight() - offsetHeight) / 3; popup.setPopupPosition(left, top); } }); popup.show(); } 

Hope this help.

0
source

Source: https://habr.com/ru/post/1332710/


All Articles