首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GWT PopupPanel只出现一次

GWT PopupPanel只出现一次
EN

Stack Overflow用户
提问于 2013-10-03 17:18:09
回答 2查看 803关注 0票数 0

我正在使用GWT-弹出面板,代码如下:

私有静态类MyPopup扩展PopupPanel {

代码语言:javascript
复制
        public MyPopup() {
          // PopupPanel's constructor takes 'auto-hide' as its boolean parameter.
          // If this is set, the panel closes itself automatically when the user
          // clicks outside of it.
          super(true);

          // PopupPanel is a SimplePanel, so you have to set it's widget property to
          // whatever you want its contents to be.
          setWidget(new Label("Click outside of this popup to close it"));

        }
      }



public void onModuleLoad() {

     final Button b1 = new Button("About");
        b1.addClickHandler(new ClickHandler() {
          public void onClick(ClickEvent event) {
            final MyPopup g = new MyPopup();
            g.setWidget(RootPanel.get("rightagekeyPanel"));
            g.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
                public void setPosition(int offsetWidth, int offsetHeight) {
                  g.setPopupPosition(b1.getAbsoluteLeft(), b1.getAbsoluteTop());
                  g.setAutoHideEnabled(true);
                }
              });

            g.setVisible(true);
            g.setWidth("500px");
            g.setHeight("500px");

            g.show();

          }
        });

它确实在单击按钮b1时出现,但在第二次单击按钮时则不会出现。怎么啦?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-03 17:39:54

使一个弹出窗口,在您的ClickHandler之外,在与您的Button相同的水平。你也不需要那个PositionCallback来集中你的弹出窗口。您只需调用g.center()就可以显示并对其进行居中处理。GWT支持页面上的一个已知问题是,如果不为GWT支持页面设置宽度,它将无法正确地对中。如果你给弹出一个合适的宽度,它就会正确地居中。

没有再次显示的原因是因为您删除了RootPanel.get("rightagekeyPanel")中的小部件并将其放入弹出窗口。下一次你尝试这样做的时候,它就不再存在了。

一个小部件一次只能在一个地方,所以如果您从它的父部件中删除它,用一个变量或什么来跟踪它,这样您就可以重用它了。否则,您必须重新实例化小部件。

代码语言:javascript
复制
public void onModuleLoad() {

    final Button b1 = new Button("About");
    final MyPopup g = new MyPopup(); //create only one instance and reuse it.
    g.setAutoHideEnabled(true);
    g.setSize("500px", "500px"); //sets width AND height


    b1.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {

            g.setWidget(RootPanel.get("rightagekeyPanel"));//DON'T DO THIS.

            g.center();//will show it and center it.
        }
    });
}
票数 1
EN

Stack Overflow用户

发布于 2015-08-14 10:46:34

只需说在我的例子中,我必须添加一些小部件来使PopUpPanel出现。尝试使用标签确保弹出窗口正在显示。

代码语言:javascript
复制
    PopupPanel popup = new PopupPanel();    
    popup.setVisible(true);
    popup.center();
    popup.show();
    popup.setWidth("500px");
    popup.setHeight("500px");
    popup.add(new Label("Test"));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19165280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档