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

发布于 2024-12-17 14:01:08 字数 1277 浏览 0 评论 0原文

我正在使用 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);

谢谢, -

I'm using GWT 2.4. I want to construct content sections using the StackLayoutPanel widget. Howevr, I'm having trouble sizing the widget vertically to take up as much space as possible. I'm discovering

    p.setHeight("100%");

doesn't actually do anything. Does anyone have any advice for calculating the proper height for the StackLayoutPanel so that it takes up as much space as possible but not more? Here's the code I'm using ...

    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;

Here is the code that ultimately calls the StackLayoutPanel. Notice that the parent widget, "ScrollPanel", sets height="100%", but that has no effect on causing the StacklayoutPanel to fill out all of its space.

            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);

Thanks, -

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风向决定发型 2024-12-24 14:01:08

调整任何类型的 LayoutPanel 大小的最佳方法是将其添加到另一个 LayoutPanel 并从父面板设置其大小。直接设置大小永远不会像我想要的那样有效。

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

关于 LayoutPanel 有很多东西需要学习。不过,一旦正确设置它们,它们的使用就非常自然,并且您可以使用它们进行许多精确布局。

The best way to size a LayoutPanel of any type is to add it to another LayoutPanel and set its size from the parent panel. Setting the size directly never works like I want it to.

This a pretty different setup from the other GWT widgets, which just want to be added and sized. You can read about it at http://code.google.com/webtoolkit/doc/latest/DevGuideUiPanels.html#LayoutPanels .

There's a lot to learn about LayoutPanels. Once you've got them set up properly, though, they're very natural to use, and you can do a lot of precision layout with them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文