我正在使用GWT-弹出面板,代码如下:
私有静态类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时出现,但在第二次单击按钮时则不会出现。怎么啦?
发布于 2013-10-03 17:39:54
使一个弹出窗口,在您的ClickHandler之外,在与您的Button相同的水平。你也不需要那个PositionCallback来集中你的弹出窗口。您只需调用g.center()就可以显示并对其进行居中处理。GWT支持页面上的一个已知问题是,如果不为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.
}
});
}发布于 2015-08-14 10:46:34
只需说在我的例子中,我必须添加一些小部件来使PopUpPanel出现。尝试使用标签确保弹出窗口正在显示。
PopupPanel popup = new PopupPanel();
popup.setVisible(true);
popup.center();
popup.show();
popup.setWidth("500px");
popup.setHeight("500px");
popup.add(new Label("Test"));https://stackoverflow.com/questions/19165280
复制相似问题