2011-11-22 20 views
1

我正在使用GWT 2.4。我想使用StackLayoutPanel小部件構建內容部分。不過,我無法垂直調整窗口小部件的大小以佔用儘可能多的空間。我在發現GWT:我如何正確設置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); 

謝謝, -

回答

0

最佳大小的方式的任何類型的LayoutPanel是將其add到另一個LayoutPanel並從父面板設置其大小。直接設置尺寸從來不會像我想要的那樣工作。

這是一個與其他GWT小部件完全不同的設置,它只是想添加和調整大小。你可以在http://code.google.com/webtoolkit/doc/latest/DevGuideUiPanels.html#LayoutPanels上閱讀。

有很多要了解LayoutPanel s。但是,一旦你將它們設置正確,它們就很自然地使用了,你可以用它們做很多精確的佈局。

+0

嗨,我已經這麼做了 - 我包含上面的代碼。我將父級ScrollPanel的高度設置爲100%,但StackLayoutPanel不調整以適合父級的高度。 StackLayoutPanel在這方面是獨一無二的嗎? – Dave