PDA

View Full Version : CenterLayoutContainer : Container misses the Resize command ?



hermann.rangamana
27 Jan 2012, 2:56 AM
On gxt 3.0.0 beta 2, i have an simple CenterLayoutContainer with a single panel inside it (a copy-paste from the showcase actually). But i was surprised, the content of my container is not centered, but located in the upper-left side of the my screen!
Here is my listing


public class CenterLayoutExample implements EntryPoint {


public void onModuleLoad() {
CenterLayoutContainer con = new CenterLayoutContainer();
ContentPanel panel = new ContentPanel();
panel.setBodyStyle("padding: 6px");
panel.setHeadingText("CenterLayout");
panel.add(new Label("I should be centered"));
panel.setWidth(200);
con.add(panel);
RootLayoutPanel.get().add(con);
}
}


BUT, if i manually resize the browser window, then the container is moved to the center of my browser window. (cf images attached : first image, at the startup of the application ; second image, after i manually resize the application).
If i add a deffered command to trigger a resize operation on the RootLayoutPanel, the container is immediately when i start the application.


Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
RootLayoutPanel.get().onResize();
}
});

So my assumption is that the container ignores the some resize operation at the startup of the application ...

rohdef
31 Jan 2012, 12:03 AM
Try wrapping the CenterLayoutContainer into a SimpleContainer if I recall correctly that solved my problems. This is probably due some layout calls that the underlying GWT doesn't do (probably due to it not being GXT), although I think I had similar problems in some GXT containers.


public class CenterLayoutExample implements EntryPoint {

public void onModuleLoad() {
SimpleContainer outerContainer = new SimpleContainer();
CenterLayoutContainer con = new CenterLayoutContainer();
ContentPanel panel = new ContentPanel();
panel.setBodyStyle("padding: 6px");
panel.setHeadingText("CenterLayout");
panel.add(new Label("I should be centered"));
panel.setWidth(200);
con.add(panel);
outerContainer.setWidget(con);
RootLayoutPanel.get().add(outerContainer);
}
}

sven
31 Jan 2012, 12:12 AM
You need to size your CenterLayoutContainer. Else it will not work correctly.

hermann.rangamana
31 Jan 2012, 1:02 AM
Thanks for your reply.

But what if i want my container to fill the whole browser window ? I'd expected the same behavior as straight gwt panels which automatically fill the window browser when i add them to RootLayoutPanel.get(). It's kind of difficult to get interoperability between panels of gxt and those from gwt if the behave differently when added to RootLayoutPanel.
I think it's a bug.

thanks

HR

sven
31 Jan 2012, 1:16 AM
Sorry i missed that you are using RootLayoutPanel. In that case you simple need to call forceLayout on it:

RootLayoutPanel.get().forceLayout();

hermann.rangamana
31 Jan 2012, 1:51 AM
Thanks for your reply, steven.

Hermann