gwt 弹出窗口未居中

发布于 2024-10-08 13:21:45 字数 625 浏览 0 评论 0原文

我使用 gwt 弹出窗口显示一些消息,但它没有显示在 中心 如果我调用 popup.center(),则显示事件。实际上它并不居中 只有第一次,如果我关闭它并再次打开它,一切都会好的, 但不是第一次。如何解决这个问题?

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

我在 http://www.devcomments.com/ 上发现了这个问题gwt-Popup-is-not-centered-at107182.htm,今天我也遇到了这个问题。我找到了答案,并将其发布在这里以供将来参考。

I use gwt popup to show some messages, but it is not displayed in the
center
of the display event if i call popup.center(). Actually it is not centered
only the first time, if i close it and open it again every thing is ok,
but not the first time. How to fix that?

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 on http://www.devcomments.com/gwt-Popup-is-not-centered-at107182.htm, and today I have had this problem too. I found the answer and i will post it here for future reference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

莫相离 2024-10-15 13:21:45

我发现问题是当您将弹出窗口居中时,图像未加载完成。第一次发生这种情况只是因为第二次图像被浏览器以某种方式兑现。

解决方案是将其也集中在 onLoad 事件上。

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();
    }
});

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

The solution is to center it on the onLoad event as well.

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();
    }
});
梦魇绽荼蘼 2024-10-15 13:21:45

我也有这个问题。您必须调用中心两次的原因是,当弹出窗口“隐藏”时,弹出容器实际上已从 DOM 中删除。这是有问题的,因为您的弹出窗口现在必须“显示”弹出窗口的内容,然后您才能检查图像是否已加载。

建议实现的问题是,如果图像未缓存,则对 center() 的第一次调用将错误地完成。第二次致电中心将纠正它。在浏览器上,这会导致弹出对话框发生变化(看起来很糟糕)。

我会推荐以下内容:
1. 将等待旋转器放在同一显示器中并首先显示。
2. 调用 loadHandler 后,显示图像、隐藏微调器并重新居中。

I had this problem as well. The reason that you have to call center twice is because the popup container is actually removed from the DOM when the popup is "hidden". This is problematic because your popup has to now "show" the contents of the popup before you can check that the image is loaded.

The issue with the implementation recommended is that the first call to center() will be done incorrectly if the image is not cached. The second call to center will correct it. On the browser, this causes a shift of the popup dialog box (which looks pretty bad).

I would recommend the following:
1. Put a waiting spinner in the same display and show that initially.
2. One the loadHandler is called, display the image, hide the spinner, and recenter.

    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();
        }

希望这有帮助。

    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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文