PDA

View Full Version : Resize Window on expand/collapse



rian.k
25 Jun 2009, 3:50 AM
Hi,
I want a Dialog with a collapsible FieldSet with the functionality to resize the Dialog on expand / collapse of the FieldSet. How could I achive this?

The following code doesn't work well, but am I going about this the right way?



Dialog d = new Dialog();

d.setHeading("Info");
d.setSize(200,120);
d.setBodyStyle("fontWeight:bold; padding:13px;");
d.setHideOnButtonClick(true);
d.setButtons(Dialog.OK);
d.setLayout(new FitLayout());

FieldSet fieldSet = new FieldSet() {
private int collapsedWidth;
private int collapsedHeight;
private int collapsedDialogWidth;
private int collapsedDialogHeight;

@Override
protected void onRender(Element element, int i) {
super.onRender(element, i);
collapse();
collapsedWidth = el().getWidth();
collapsedHeight = el().getHeight();
collapsedDialogWidth = d.getWidth();
collapsedDialogHeight = d.getHeight();
}

@Override
protected void onExpand() {
super.onExpand();
d.setSize(collapsedDialogWidth + (this.el().getWidth() - collapsedWidth),
collapsedDialogHeight + (this.el().getHeight() - collapsedHeight));
}

@Override
protected void onCollapse() {
super.onCollapse();
d.setSize(collapsedWidth, collapsedHeight);
}
};

fieldSet.setHeading("short info");
fieldSet.setCollapsible(true);
fieldSet.setLayout(new FitLayout());

TextArea textArea = new TextArea();
textArea.setValue("some long msg");
textArea.setHideLabel(true);
fieldSet.add(textArea);

d.add(fieldSet);
thanks