0

我正在使用带有以下代码的 GWT-Popup-Panel:

私有静态类 MyPopup 扩展 PopupPanel {

        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 时确实会出现,但第二次单击时不会出现。怎么了?

4

2 回答 2

1

制作一个弹出窗口,在您的之外,ClickHandler与您的Button. 您也不需要它PositionCallback来使您的弹出窗口居中。你可以打电话g.center()来显示它并居中。这是 GWT 支持页面上的一个已知问题,如果您不为其设置宽度,它将无法正确居中。如果您为弹出窗口提供适当的宽度,它将正确居中。

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

一个小部件一次只能在一个地方,因此如果您将其从其父级中删除,请使用变量或其他东西对其进行跟踪,以便您可以重复使用它。否则,您必须重新实例化小部件。

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.
        }
    });
}
于 2013-10-03T17:39:54.837 回答
1

只是说在我的情况下,我必须添加一些小部件才能使 PopUpPanel 出现。尝试使用标签来确保弹出窗口正在显示。

    PopupPanel popup = new PopupPanel();    
    popup.setVisible(true);
    popup.center();
    popup.show();
    popup.setWidth("500px");
    popup.setHeight("500px");
    popup.add(new Label("Test"));
于 2015-08-14T10:46:34.180 回答