Centre a widget at the top of the screen

5 views
Skip to first unread message

Hilco

unread,
Jul 30, 2010, 11:25:19 PM7/30/10
to gwt-mosaic
I'm trying to center a widget at the top of the screen but I don't
seem to be able to. At least not without explicitly setting some CSS
on the widget's element.

public class MosaicView extends ViewImpl implements MosaicPage.View
{ // Using GWT-Platform 0.3
private final LayoutPanel panel;

@Inject
public MosaicView() {
// GWT-Mosaic 0.4.0-rc4
BorderLayout borderLayout = new BorderLayout();
panel = new LayoutPanel(borderLayout);
FillLayout fillLayout = new FillLayout();

fillLayout.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
LayoutPanel headerPanel = new LayoutPanel(fillLayout);
final Label header = new Label("HEADER");
headerPanel.add(header);
panel.add(headerPanel, new BorderLayoutData(Region.NORTH));
RootLayoutPanel.get().add(panel);
}

@Override
public Widget asWidget() {return panel;}
}

This puts "HEADER" in the top left corner of the screen, not in the
centre as I had expected. What am I doing wrong? Why is the
HasHorizontalAlignment.ALIGN_CENTER ignored?

Hilco

unread,
Aug 5, 2010, 1:09:38 PM8/5/10
to gwt-mosaic
Does anyone know? Am I doing something wrong? Is this a bug?

Mike Warne

unread,
Aug 5, 2010, 3:11:55 PM8/5/10
to gwt-m...@googlegroups.com
I am also struggling with centering content in a border layout.  

Try wrapping your widget in another BoxLayout Panel.
Then add the BoxLayout to the NORTH region of your BorderLayout.

I am doing something similar, and it seems to be ok.

Mike.


--
You received this message because you are subscribed to the Google Groups "gwt-mosaic" group.
To post to this group, send email to gwt-m...@googlegroups.com.
To unsubscribe from this group, send email to gwt-mosaic+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gwt-mosaic?hl=en.


Reply all
Reply to author
Forward
0 new messages