tags:

views:

383

answers:

2

Hi

I'm using Google web toolkit to develop a small login page. I'm using GWT Designer. My problem is that the rootPanel is not being displayed at the centre but at the top-left corner of the browser. How can I put it at the centre of the page plz?

Thanks and regards, Krt_Malta

+2  A: 

You don't need GWT at all for this, but rather just CSS/HTML.

<body>
  <div id="root" style="width: 100px; margin: auto;">
</body>
Jason Hall
nopes didn't work :(
Krt_Malta
My mistake, you have to specify a width to make it work. And this will only center it horizontally, not vertically.
Jason Hall
A: 

You cannot display the RootPanel in the center of the screen since the RootPanel is the <body> of the document itself, it has no position.

What you want is to add a base panel to the RootPanel which will be centered horizontally. That new panel (suppose a FlowPanel) will hold all other widgets, and that panel can have a position, which means it can be centered.

Something along these lines should do:

RootPanel rp = RootPanel.get();
FlowPanel fp = new FlowPanel();

fp.add(allYourWidgets);
fp.addStyleName('center'); // where center is a css rule with "margin: auto;"

rp.add(fp);
Yuval A
RootPanels don't have to be <body> elements. If you specify an ID in RootPanel.get() it will select any element with that ID to be your root panel.
Jason Hall