0

我被要求在 GWT Composite 中放置一个“完成”按钮(尽管已经有关闭图标),它应该在单击时简单地关闭窗口。不幸的是,我找不到.close()实现它的方法。如何做呢?

在此处输入图像描述

我有一个包含复合组件的 UserDialog 类,我将其命名为 UserComposite。UserDialog 扩展为 CustomDialogBox,CustomDialogBox 扩展为 DialogBox 类:

public class UserDialog extends CustomDialogBox {    
    private UserComposite c = new UserComposite();
    // more codes here
    private FlowPanel getFlowPanel() {
        if (p instanceof Panel && c instanceof Composite) {
            p.setSize(WIDTH, HEIGHT);
            p.add(c);
        }
        return p;
    } 
}

然后这是我的 UserComposite

public class UserComposite extends Composite {
   // codes here
   @UiHandler("doneButton")
   void onDoneButtonClick(ClickEvent event) {
      this.removeFromParent();
   }
}

我尝试了 removeFromParent() 但 UserComposite 仅从父级中删除,导致一个空的对话框。

在此处输入图像描述

4

2 回答 2

4

@先生。Xymon,如果您指的是 PopupPanel 的实例或 PopupPanel 的任何子类的实例,则按窗口,您可以使用以下内容:

popupPanel.hide();
于 2012-09-29T08:03:14.857 回答
4

您需要隐藏对话框,而不是复合。一种方法是将对话框的引用传递给 UserComposite 构造函数,然后使用该引用在对话框上调用 hide()。可能是这样的:

public class UserDialog extends CustomDialogBox {
    private UserComposite c = new UserComposite(this);
    ...
}

public class UserComposite extends Composite {
    private DialogBox parentDialog;

    public UserComposite(DialogBox parentDialog) {
        this.parentDialog = parentDialog;
    }

    @UiHandler("doneButton")
    void onDoneButtonClick(ClickEvent event) {
        parentDialog.hide();
    }
}
于 2012-09-29T16:50:12.597 回答