PDA

View Full Version : [FIXED] [1.0 beta3] CenterLayout not center internal panel with BorderLayout



dav
21 May 2008, 1:36 PM
Hi,
I am trying to center a panel in a ViewPort. When panel had FitLayout everything was be fine, but when I set BorderLayout and add child North panel I got not centered parent panel (centerPanel).

Here is the code :



ViewPort viewport = new Viewport();
viewport.setLayout(new CenterLayout());

ContentPanel centerPanel = new ContentPanel(new BorderLayout());
centerPanel.setHeading("Centered");
centerPanel.setHeight(125);
centerPanel.setWidth(530);
centerPanel.setFrame(true);

ContentPanel northPanel = new ContentPanel(new FitLayout());
northPanel.setBorders(true);
northPanel.setHeaderVisible(false);
northPanel.add(new Html("<p>Header text</p>"));
BorderLayoutData data = new BorderLayoutData(LayoutRegion.NORTH, 30);
data.setMargins(new Margins());
northPanel.setData(data);

centerPanel.add(northPanel, data);

viewport.add(centerPanel);
RootPanel.get().add(viewport);
I try to debug with firebug and take result as shown on screenshot below.
When I manually remove (in firebug)
position: absolute; style attribute from centerPanel div tag panel rendered normaly in the center of viewport.

May be simplest solution is redefine 'position' attribute from java code after centerPanel creation (but all my attempts has no results - I cannot change this property). Any other fixes ?

dav
23 May 2008, 4:00 PM
My solution is add Render event handler and set 'position' style attribute to 'static'. But this not bugfix is a little hack.



centerPanel.addListener(Events.Render, new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent be) {
centerPanel.setStyleAttribute("position", "static");
}

});

darrellmeyer
25 May 2008, 10:04 PM
There was a bug in BorderLayout, the container should only be changed to position: relative if its position value starts as static. Fix is in SVN.