PDA

View Full Version : [CLOSED] CenterLayout problem when resizing



zaccret
13 May 2008, 11:41 PM
With the following code, my panel is well centered when I launch the web app in hosted mode. When I resize/expand the window the text field is going out of its container.



public void onModuleLoad() {
Viewport viewport = new Viewport();
Container<Component> loginPanel = new Container<Component>();
loginPanel.setLayout(new CenterLayout());

ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setHeading("Login");
panel.setWidth(100);
Button loginButton = new Button("Login");
panel.add(new TextField());
panel.add(loginButton);
loginPanel.add(panel);
viewport.add(loginPanel);

RootPanel.get().add(viewport);
}

zaccret
13 May 2008, 11:46 PM
Maybe I should put the content panel directly in the viewport like this :


public void onModuleLoad() {
Viewport viewport = new Viewport();
viewport.setLayout(new CenterLayout());

ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setHeading("Login");
panel.setWidth(100);
Button loginButton = new Button("Login");
panel.add(new TextField());
panel.add(loginButton);
viewport.add(panel);

RootPanel.get().add(viewport);
}
Here it works but I'm not sure that we have a normal behaviour in my first post.

gslender
14 May 2008, 1:40 AM
Well, the difference is that you didn't set a layout on viewport in the 1st example, but you did on the 2nd. So I guess I'd try the 1st example again, this time putting a layout on the viewport (maybe FitLayout) to ensure you are comparing apples with apples?

zaccret
14 May 2008, 7:37 AM
Right, if I add
viewport.setLayout(new FitLayout()); then it works. I thought that every component had a default layout (FitLayout). Anyway, is it really a normal behaviour ? Maybe it could raises an exception when no layout has been set ?

gslender
14 May 2008, 1:07 PM
default layout is a FlowLayout

darrellmeyer
14 May 2008, 2:55 PM
I added that FlowLayout is the default layout to container's javadocs.

zaccret
14 May 2008, 10:04 PM
Thanks, Darell, for the javadoc ;). Anyway, even with FlowLayout for the viewport, why is the textfield going out of its container (which has CenterLayout) ?

gslender
14 May 2008, 11:45 PM
I'd guess because there is no size bounding the container in the viewport, the layout "lays out" the children and because flow says, just be as big as you need, the container just sizes wheeeellly big like??? this is my opinon so Darrell will probably correct where I'm wrong...