将DynamicForm水平对齐到VLayout的中心

时间:2015-12-16 15:36:04

标签: smartgwt dynamicform

有没有办法将DynamicForm水平对齐到VLayout的中心?我已经尝试了在this展示演示中所做的事情,但它不适用于表单(它确实可以正常运行IButton)。

这是我的代码:

public class PreferencesStackSection extends SectionStackSection {

    private static final String SAVE_ICON = "icons/save.png";
    private static final int COMPONENT_GAP = 10;

    // Object used to get access to internationalization constants and messages
    private BMSimulatorConstants constants = GWT.create(BMSimulatorConstants.class);

    private DataSource ds;
    private DynamicForm form;
    private IButton saveBtn;

    public PreferencesStackSection(String title) {
        super(title);
        ds = DataSource.get("preferences");
        buildPreferencesLayout();
    }


    private void buildPreferencesLayout() {
        VLayout layout = new VLayout(COMPONENT_GAP);
        layout.setMargin(COMPONENT_GAP * 2);
        layout.setDefaultLayoutAlign(Alignment.CENTER);
        createPreferencesForm(layout);
        createSaveButton(layout);
        this.addItem(layout);
    }

    private void createPreferencesForm(VLayout layout) {
        form = new DynamicForm();
        form.setNumCols(1);
        form.setTitleOrientation(TitleOrientation.TOP);
        form.setDataSource(ds);
        layout.addMember(form);
    }

    private void createSaveButton(VLayout layout) {

        saveBtn = new IButton(constants.preferencesSaveButton());
        saveBtn.setIcon(SAVE_ICON);
        saveBtn.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {

                DSCallback callback = new DSCallback() {
                    public void execute(DSResponse response, Object rawData, DSRequest request){
                        SC.say(constants.preferencesSavedOK());
                    }
                };

                form.saveData(callback);
            }
        });
        layout.addMember(saveBtn);
    }
}

1 个答案:

答案 0 :(得分:0)

这解决了问题(线的顺序对于它的工作非常重要):

private void createPreferencesForm(VLayout layout) {
    form = new DynamicForm();
    form.setDataSource(ds);
    form.setNumCols(1);
    form.setTitleOrientation(TitleOrientation.TOP);
    layout.addMember(form);
    form.setWidth("70%");
    for(FormItem item: form.getFields()){
        item.setWidth("*");
    }
}