Question

I`m using GWT-Popup-Panel with the following code:

private static class MyPopup extends 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();

          }
        });

It does appear when clicking Button b1, but not when clicking it the second time. What is wrong?

Was it helpful?

Solution

Make one popup, outside of your ClickHandler, at the same level as your Button. You also don't need that PositionCallback to center your popup. You can just call g.center() to show it and center it. It's a known issue on the GWT support pages that it won't center properly if you don't set a width to it. It will center properly if you give your popup a proper width.

The reason it doesn't show again is because you remove the widget inside RootPanel.get("rightagekeyPanel") and put it into your popup. It is no longer there the next time you try to do it.

A widget can only be in one place at a time, so if you remove it from its parent, keep track of it with a variable or something, so you can re-use it. Otherwise, you must re-instantiate the widget.

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

OTHER TIPS

Just say in my case I had to add some widget to make the PopUpPanel appear. Try using a label to make sure the Popup is showing.

    PopupPanel popup = new PopupPanel();    
    popup.setVisible(true);
    popup.center();
    popup.show();
    popup.setWidth("500px");
    popup.setHeight("500px");
    popup.add(new Label("Test"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top