There is something that I probably don't understand. I try to create a vertical layout container and add elements to it on button click. But this doesn't work, the elements are not drawn. What is the problem?
Also when I try to add Label element instead of Button, it draws them in one horizontal line instead of putting them vertically.
Code:
public class MYTest implements EntryPoint {
public void onModuleLoad() {
final LayoutContainer postsContainer = new LayoutContainer();
VBoxLayout layout = new VBoxLayout();
layout.setPadding(new Padding(5));
layout.setVBoxLayoutAlign(VBoxLayout.VBoxLayoutAlign.LEFT);
postsContainer.setLayout(layout);
Button b = new Button("add new element");
b.addListener(Events.OnClick,new Listener<ButtonEvent>() {
public void handleEvent(ButtonEvent buttonEvent) {
postsContainer.add(new Button("New Label"));
}
});
postsContainer.add(b);
postsContainer.add(new Button("New Label"), new VBoxLayoutData(new Margins(0, 0, 5, 0)));
postsContainer.add(new Button("New Label2"), new VBoxLayoutData(new Margins(0, 0, 5, 0)));
Viewport viewport = new Viewport();
viewport.setLayout(new FitLayout());
viewport.add(postsContainer);
RootPanel.get().add(viewport);
}