我希望setHorizontalAlignment将我的两个按钮从左侧移到中间。知道为什么这不起作用吗?所有相关代码在下面,非常简单。
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());
}
}
最佳答案
当您不对水平面板赋予任何宽度时,它将占用其内容宽度的总和。因此,HasHorizontalAlignment.ALIGN_RIGHT
,HasHorizontalAlignment.ALIGN_LEFT
或任何其他对齐方式对于其在给定区域中的拟合都无关紧要。尝试设置以下内容,
buttonPane.setwidth(100%);
buttonPane.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTRE);
如果这也行不通,则必须使用API设置单元格对齐
setCellHorizontalAlignment(Widget w,HasHorizontalAlignment.HorizontalAlignmentConstant align);