2011-12-30 41 views
0

我正在使用RowLayout作爲容器。佈局具有水平方向。我沒有指定容器的任何高度。我期望它能根據孩子的身高來獲得身高。但GXT根本不會顯示容器的子項,除非我明確指定容器的高度。使用RowLayout不會給父母高度

有沒有辦法使容器獲得高度取決於它的孩子,而沒有指定水平方向使用RowLayout時的高度?

public class RowLayoutNoHeight implements EntryPoint { 
public void onModuleLoad() { 
    ContentPanel cp = new ContentPanel(); 
    cp.setSize(300, 400); 

    final LayoutContainer innerPanel = new LayoutContainer(); 
    innerPanel.setBorders(true); 
    innerPanel.setLayout(new RowLayout(Orientation.HORIZONTAL)); 

    Text firstText = new Text("First text"); 
    Text secondText = new Text("Second text"); 

    // Here, innerPanel will not have any height. That is, I don't see the 
    // text components in the UI 
    innerPanel.add(firstText, new RowData(1, -1)); 
    innerPanel.add(secondText, new RowData(1, -1)); 

    Viewport viewPort = new Viewport(); 

    cp.add(innerPanel); 
    viewPort.add(cp); 
    RootPanel.get().add(viewPort); 
    } 
} 

GWT版本 - 2.4 GXT版本 - 2.2.5 瀏覽器 - IE 8和Firefox 7.0.1

感謝, Ganesh神

回答

0

你給你的innerPanel佈局僅會影響該面板中的小部件,只需添加

cp.setLayout(new RowLayout(Orientation.HORIZONTAL)); 

在您聲明主面板之後。

+0

在主容器上設置佈局不起作用。它只有在我添加指定高度的內部面板時纔有效。這是使用代碼cp.add(innerPanel,新的RowData(1,100)),但我的目的是讓內部面板根據孩子的身高自動調整高度。 – 2012-01-09 12:56:47

0

如果你可以爲你的容器做一個佈局(真),你會發現你的問題馬上消失!