Tuesday, 26 July 2011

GWT: how to make and show a PopupPanel

Code sample for creating and showing a simple popup in gwt which has some styling, is centred in the browser and which contains a single string and a single button to close/hide the popup:

final PopupPanel popup = new PopupPanel(false);
popup.addStyleName(Resources.instance.styles().popup());
Button btnClose = new Button("Close");
btnClose.addClickHandler(new ClickHandler()
{
 @Override
 public void onClick(ClickEvent event) { popup.hide(); }
});
FlowPanel fpPopupContents = new FlowPanel();
fpPopupContents.add(new Label("My message"));
fpPopupContents.add(btnClose);
popup.setWidget(fpPopupContents);
popup.center();

No comments: