开发者

Display rootPanel at centre GWT

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?


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

<body>
  <div id="root" style="width: 100px; margin: auto;">
</body>


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);


The RootPanel gets a reference to the panel to which all your application widgets must ultimately be added. (RootPanel returns the reference to the document’s body in the browser.) You would generally inject the starting point of your application into an HTML page. You can do this by using the RootPanel class’s get() methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜