GWT:如何正确设置StackLayoutPanel的高度?

时间:2011-11-22 14:57:47

标签: gwt height panel

我正在使用GWT 2.4。我想使用StackLayoutPanel小部件构造内容部分。但是,我无法垂直调整小部件的大小以占用尽可能多的空间。我发现了

    p.setHeight("100%");

实际上并没有做任何事情。有没有人有任何建议来计算StackLayoutPanel的正确高度,以便它占用尽可能多的空间但不是更多?这是我正在使用的代码......

    final StackLayoutPanel p = new StackLayoutPanel(Unit.EM);
    p.setHeight("100%");
    int i=0;
    for (final Node node : nodes) { 
        if (node != null) { 
            final Widget childWidget = getWidget(node.getChildren());
            if (childWidget != null) { 
                final String sectionTitle = node.getAttributes().get(NAME_ATTR) != null ? node.getAttributes().get(NAME_ATTR).getValue() : "Section " + (i+1);
                p.add(childWidget, sectionTitle, 2);
            }   // if
        }   // if
        i++;
    }   // for
    return p;

这是最终调用StackLayoutPanel的代码。请注意,父窗口小部件“ScrollPanel”设置height =“100%”,但这对使StacklayoutPanel填满其所有空间没有影响。

            final ScrollPanel childpanel = new ScrollPanel();
            childpanel.setHeight("100%");
            // Below, a StackLayoutPanel is returned as the child widget
            final Widget childWidget = xmlToHtmlService.getWidget(tabNode.getChildren());
            childpanel.add(childWidget);

谢谢, -

1 个答案:

答案 0 :(得分:0)

确定任意类型的LayoutPanel大小的最佳方法是add它与另一个LayoutPanel并从父面板设置其大小。直接设置大小永远不会像我想要的那样。

这与其他GWT小部件完全不同,只是想添加和调整大小。您可以在http://code.google.com/webtoolkit/doc/latest/DevGuideUiPanels.html#LayoutPanels了解相关信息。

有很多关于LayoutPanel的了解。但是,一旦你正确设置它们,它们使用起来非常自然,你可以用它们做很多精确的布局。

相关问题