PDA

View Full Version : BoxLayoutContainer adds all new widgets at position 0, not at the end



raivis
24 Nov 2011, 1:44 AM
HBoxLayoutContainer and VBoxLayoutContainer adds new widgets at position 0 (on top of each other), not at the end of the widget list, if widgets are added at runtime. Widgets get in place only after container gets resized.
rev 1806

First 5 ToggleButtons, that are being added in a constructor, are placed correctly, but when you click any of those buttons to add new at runtime, you will see that new buttons are being placed on top of the first button.



public class GxtModule implements EntryPoint, ClickHandler {
HBoxLayoutContainer hlc;


@Override
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
hlc = new HBoxLayoutContainer();
rootPanel.add(hlc);
for (int i = 0; i < 5; i++) {
ToggleButton b = new ToggleButton("Button " + i);
b.setLayoutData(new BoxLayoutData(new Margins(0, 5, 0, 0)));
b.addDomHandler(this, ClickEvent.getType());
hlc.add(b);
}
}


@Override
public void onClick(ClickEvent event) {
ToggleButton b = new ToggleButton("Button " + hlc.getWidgetCount());
b.setLayoutData(new BoxLayoutData(new Margins(0, 5, 0, 0)));
b.addDomHandler(this, ClickEvent.getType());
hlc.add(b);
}
}

sven
24 Nov 2011, 1:45 AM
Try to call forceLayout after adding them.

raivis
24 Nov 2011, 1:59 AM
calling forceLayout() fixes that. Is it supposed to be like that or forceLayout() won't be needed in a final version?

DarekKay
24 Nov 2011, 2:54 AM
It's always have been like that (previously doLayout(boolean force)). Consider adding 100 widgets at runtime - it wouldn't make any sense to layout them after each component added.

raivis
24 Nov 2011, 3:45 AM
Yes, I thought about it just few seconds after posting the question.