2011-12-14 2 views
0

J'utilise GWT 2.4. J'ai vue avec un certain contenu simple ...GWT: Comment centrer le contenu dans un panneau?

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

Je voudrais que ce contenu soit centrée horizontalement et verticalement dans le panneau contenant, qui est un FlowPanel, si cela importe. Comment je fais ça? Merci, - Dave

Répondre

1

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

5

Je sais comment le faire dans un panneau vertical.

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

Travaillé comme un charme CSS est source de confusion sur ce problème. Merci! Y a-t-il un parallèle CSS? –

+1

.setHeight ("100%"); ne fonctionne plus. Essayez .setHeight (Window.getClientHeight() + "px"); –

2

si vous deviez mettre votre FlowPanel comme un enfant direct de votre RootPanel, vous pouvez essayer de définir sa height à 100%. donc si vous avez seulement une grille en tant que composant enfant pour votre conteneur, vous pouvez définir ses alignements comme ceci:

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

Mais si vous changez d'avis et vous passez à UiBinder, vous pouvez faire quelque chose comme cela:

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