GWT:如何正确设置 StackLayoutPanel 的高度?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调整任何类型的
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 toadd
it to anotherLayoutPanel
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
LayoutPanel
s. 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.