在SectionStackSection中,如何更改setControls(Canvas ...)中使用的控件的位置?

时间:2012-03-08 15:09:40

标签: smartgwt

SectionStackSection中,如何更改setControls(Canvas ...)

中使用的控件的位置

目前,它始终在右侧,如何将其设置为左侧或中央?

2 个答案:

答案 0 :(得分:1)

您可以使用HLayout作为控件Canvas。 HLayout可以将您希望在第一个位置设置的控件作为其成员,但现在您可以在HLayout中控制它们的对齐,从而控制SectionStackSection。您可以在下面看到一个简单的示例:

    SectionStack sectionStack = new SectionStack();
    sectionStack.setWidth(500);
    sectionStack.setHeight(200);

    SectionStackSection sectionStackSection = new SectionStackSection("Test");
    HLayout controls = new HLayout();
    controls.setWidth(sectionStack.getWidth()*8/10);
    controls.setHeight(5);

    controls.setLayoutAlign(Alignment.LEFT);
    controls.setLayoutAlign(VerticalAlignment.CENTER);

    IButton iButton = new IButton("C");
    iButton.setAutoFit(Boolean.TRUE);
    iButton.setLayoutAlign(Alignment.LEFT);

    controls.addMember(iButton);

    sectionStackSection.setControls(controls);
    sectionStack.addSection(sectionStackSection);

使用HLayout的宽度在SectionStackSection标头内微观管理控件的显示位置。它不是一个完美的解决方案,但可以在简单的情况下工作。

答案 1 :(得分:0)

唯一可行的方法是正确处理绘制和调整大小。所以这是我的工作解决方案:

private void generateDetailsListGridHeader() {
    createControls();
    section = new SectionStackSection();
    section.setCanCollapse(false);
    section.setExpanded(true);
    section.setControls(controls);
    section.setItems(detailsListGrid);

    sectionStack = new SectionStack();
    sectionStack.setSections(section);
    sectionStack.addResizedHandler(new ResizedHandler() {

        @Override
        public void onResized(ResizedEvent event) {
            htmlFlow.setWidth(sectionStack.getWidth() >> 1);
            controls.setWidth(sectionStack.getWidth() - 10);
        }
    });
    sectionStack.addDrawHandler(new DrawHandler() {

        @Override
        public void onDraw(DrawEvent event) {
            htmlFlow.setWidth(sectionStack.getWidth() >> 1);
            controls.setWidth(sectionStack.getWidth() - 10);
        }
    });
}

private void createControls() {
    String title = "<table> <tr> <td style=\"vertical-align:middle; color:blue; font-size:15px\"> <b>Please double click a class from the left to display its instances</b> </td> </tr> </table>";
    controls = new HLayout(10);
    htmlFlow = new HTMLFlow(title);
    htmlFlow.setOverflow(Overflow.AUTO);
    DynamicForm form = new DynamicForm();
    TextItem versionSearchItem = new TextItem("version", "Version");
    form.setItems(versionSearchItem);
    controls.addMember(htmlFlow);
    controls.addMember(form);
}

通过更改onResized和onDraw中的宽度,您可以将每个控件放在任何位置!