开发者

gwt panel horizontal alignment not working

I have a GWT dialog box that looks like the following:

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

For some reason the 'buttons' panel does not obey the horizontalAlignment setting; it sticks to the left side of the outer panel. It does, however, obey the verti开发者_开发技巧alAlignment setting. Any ideas? Thanks!


Tables don't respect the parent's horizontal alignment property. Instead, set the left & right margins of the child table to "auto".

buttons.getElement().getStyle().setProperty("marginLeft", "auto"); buttons.getElement().getStyle().setProperty("marginRight", "auto");

More Info: Center a table with CSS

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜