how to get the width & height of dialog box (also calculate the actual size of dialog when it was shown) in GWT?

411 views
Skip to first unread message

Tom

unread,
Oct 4, 2013, 12:18:13 PM10/4/13
to google-we...@googlegroups.com
I have a dialogbox holding a HTMLPanel that has a flextable & 2 buttons.

So I tried myDialog.getOffsetWidth & myDialog.getOffsetHeight, it showed some result but somehow it doesn't count the size of the widgets inside HTMLPanel inside DialogBox.

how to get the width & height of dialog box (also calculate the actual size of dialog when it was shown) in GWT?

Paul Mazzuca

unread,
Oct 5, 2013, 10:37:18 AM10/5/13
to google-we...@googlegroups.com
I usually set the width and height of the contained widget explicitly  and just use the DialogBox or PopupPanel as a wrapper.  I use the following extended version of Popup panel to size the popup at 75% width and 60% height of the current window.  Basically, resizing the widget and not the dialogbox.   

public class YourAppWidgetPopupPanel extends PopupPanel {


public YourAppWidgetPopupPanel() {

super(true);

setAnimationEnabled(true);

setAutoHideEnabled(true);

setGlassEnabled(true);

}


@Override

public void setWidget(Widget widget) {

super.setWidget(widget);

int height = RootLayoutPanel.get().getOffsetHeight();

int width = RootLayoutPanel.get().getOffsetWidth();

int w = width * 3 / 4;

int h = height * 3 / 5;

widget.setWidth(w + "px");

widget.setHeight(h + "px");

center();

}


public YourAppWidgetPopupPanel(boolean autoHide) {

super(autoHide);

}


public YourAppWidgetPopupPanel(boolean autoHide, boolean modal) {

super(autoHide, modal);

}


}

Tom

unread,
Oct 5, 2013, 11:10:58 AM10/5/13
to google-we...@googlegroups.com
but we have to use dialog.setPopupPositionAndShow to get the width otherwise there no way to get the WidthHeight of dialog dynamically.
Reply all
Reply to author
Forward
0 new messages