gwt面板水平对齐不起作用

时间:2009-11-21 04:01:35

标签: gwt dialog alignment panel

我有一个GWT对话框,如下所示:

public class FooDialog extends DialogBox {

public FooDialog() {
        setText("Foo Dialog");
        VerticalPanel outer = new VerticalPanel();
        outer.setBorderWidth(3);
        outer.setSize("400px", "200px");
        outer.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
        outer.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE);

        Button cancelButton = new Button("Cancel", new ClickHandler() {
      public void onClick(ClickEvent event) {
        hide();
      }
    });

        HorizontalPanel buttons = new HorizontalPanel();
        buttons.setBorderWidth(3);
        buttons.add(cancelButton);

        outer.add(buttons);

        setWidget(outer);
    }
}

由于某种原因,“按钮”面板不遵循horizo​​ntalAlignment设置;它粘在外板的左侧。但是,它确实遵循vertialAlignment设置。有任何想法吗?谢谢!

1 个答案:

答案 0 :(得分:4)

表不尊重父级的水平对齐属性。相反,设置左和右;子表的右边距为“auto”。

buttons.getElement()。getStyle()。setProperty(“marginLeft”,“auto”); buttons.getElement()。getStyle()。setProperty(“marginRight”,“auto”);

更多信息:Center a table with CSS