1

我希望 setHorizo​​ntalAlignment 将我的两个按钮从左侧移到中间。知道为什么这不起作用吗?所有相关代码都在下面并且非常简单。

在此处输入图像描述

public void onClick(ClickEvent event) {
            final DialogBox deleteDialog = new DialogBox();
            deleteDialog.setModal(false);
            deleteDialog.setGlassEnabled(true);

            HorizontalPanel buttonPane = new HorizontalPanel();
            buttonPane.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

            buttonPane.add(deleteDialogOKButton);
            buttonPane.add(deleteDialogCancelButton);

            deleteDialog.center();      

            deleteDialog.add(buttonPane);       
            deleteDialog.setText("Delete this Station?");

            deleteDialogOKButton.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    stationService.deleteStation(station, new DeleteStationCallback());
                    deleteDialog.hide();
                }});

            deleteDialogCancelButton.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    deleteDialog.hide();
                }});

            deleteDialog.show();
            //stationService.deleteStation(station, new DeleteStationCallback());
        }
    }
4

1 回答 1

2

当您不为水平面板提供任何宽度时,它会占用其内容宽度的总和。因此HasHorizontalAlignment.ALIGN_RIGHTHasHorizontalAlignment.ALIGN_LEFT或任何其他对齐方式都无关紧要,因为它适合给定区域。尝试设置以下内容,

buttonPane.setwidth(100%);
buttonPane.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTRE);

如果这也不起作用,那么您必须使用 API 设置单元格对齐

setCellHorizontalAlignment(Widget w,HasHorizontalAlignment.HorizontalAlignmentConstant align);
于 2012-12-01T08:02:22.817 回答