2011-12-14 65 views
0

我正在使用GWT 2.4。我有一些簡單的內容的圖...GWT:如何將內容集中到面板中?

final Image ajaxImage = new Image("loading.gif"); 
    final Grid grid = new Grid(1, 2); 
    grid.setText(0, 0, "Loading..."); 
    grid.setWidget(0, 1, ajaxImage); 
    this.container = new FlowPanel(); 
    this.container.add(grid); 
    rootPanel = new SimplePanel(); 
    rootPanel.add(this.container); 

我想此內容被在含面板,這是一個FlowPanel水平,垂直居中,如果該事項。我怎麼做?

謝謝, - 戴夫

回答

1

用css? margin:0 auto;position:absolute; top:50%;

5

我知道如何在垂直面板上做到這一點。

VerticalPanel panelPrincipal3 = new VerticalPanel();//Esto es el panel central, donde se centra todo 
    panelPrincipal3.setWidth("100%"); 
    panelPrincipal3.setHeight("100%"); 
    panelPrincipal3.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); 
    panelPrincipal3.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); 
    panelPrincipal3.add(/*your panel*/);//here yo add whatever yo want, and should be centered 
+0

工作就像一個魅力CSS在這個問題上混淆。謝謝!有一個CSS並行嗎? – 2013-08-16 14:10:49

2

如果你把你的FlowPanel爲您RootPanel的直接孩子,你可以嘗試設置其height100%。所以,如果你只有一個網格,爲您的容器子組件,您可以設置它的路線是這樣的:

container.setCellHorizontalAlignment(grid, HasHorizontalAlignment.ALIGN_CENTER); 
container.setCellVerticalAlignment(grid, HasVerticalAlignment.ALIGN_MIDDLE); 

但是,如果你改變你的想法,你會切換到UiBinder,你可以這樣做這個:

<g:VerticalPanel spacing="0" width="100%" height="100%" ui:field="mainPanel"> 
    <g:Cell horizontalAlignment="ALIGN_CENTER" verticalAlignment="ALIGN_MIDDLE"> 
    <!-- content goes here --> 
    </g:Cell> 
</g:VerticalPanel>