GWT正确关闭弹出面板?

时间:2011-04-11 10:12:10

标签: gwt popup panel parent-child

我想要关闭一个弹出面板单击一个锚点,但是这个锚点可能位于几个面板中,然后通过父母进行操作并不是一个好主意。

如何让弹出面板位于锚点所在的位置?

2 个答案:

答案 0 :(得分:2)

如何将带有PopupPanel的变量传递到其他面板呢?

public class PanelWithPopup extends Composite
{
    FlowPanel thisPanel = new FlowPanel();
    PopupPanel popup = new PopupPanel();
    SomeOtherPanel otherPanel;

    public PanelWithPopup()
    {
        // pass the popup panel to the SomeOtherPanel
        otherPanel = new SomeOtherPanel(popup);

        thisPanel.add(otherPanel);
        initWidget(thisPanel);
    }
}

public class SomeOtherPanel
{
    PopupPanel popup;

    public SomeOtherPanel(PopupPanel p)
    {
        this.popup = p;
    }

    void hidePopup()
    {
        popup.hide();
    }
}

或者,如果在主面板中定义了其他面板(即SomeOtherPanel中已定义PanelWithPopup),则可以直接访问PopupPanel popup

答案 1 :(得分:0)

如果要关闭所有打开的弹出面板。例如:如果用户单击后退按钮,或者您的定位按钮触发页面更改。您可以使用此方法:

public static void closeAllPopups() {
    for (int i=0; i<RootPanel.get().getWidgetCount(); i++) {
        if (RootPanel.get().getWidget(i) instanceof PopupPanel) {
            PopupPanel popupPanel = (PopupPanel)RootPanel.get().getWidget(i);
            Scheduler.get().scheduleDeferred(() -> popupPanel.hide());
        }
    }
}