2013-03-16 53 views
1

我想知道是否有可能獲得在GWT一個GWT ScrollPanel讓孩子們的最大尺寸不滾動

com.google.gwt.user.client.ui.ScrollPanel 

對象的內部尺寸?我想創建一個ScrollPanel的孩子,它完全符合空的空間,而不用激活滾動條。

public void onModuleLoad() { 

    Window.setMargin("0px"); 

    TabLayoutPanel tabs = new TabLayoutPanel(30, Unit.PX); 

    //attach the tab panel to the body element 
    RootPanel.get(null).add(tabs); 

    //set the TabLayoutPanel to full size of the window. 
    String width = (Window.getClientWidth()) + "px"; 
    String height = (Window.getClientHeight()) + "px"; 
    tabs.setSize(width, height); 

    //create the scroll panel and activate the scroll bars 
    ScrollPanel scrollPanel = new ScrollPanel(new Button("a second button")); 
    scrollPanel.getElement().getStyle().setOverflowX(Overflow.SCROLL); 
    scrollPanel.getElement().getStyle().setOverflowY(Overflow.SCROLL); 

    //attach the scroll panel to the DOM 
    tabs.add(scrollPanel, "tab1"); 

    System.out.println(scrollPanel.getOffsetWidth());  // --> 0 
    System.out.println(scrollPanel.getOffsetHeight());  // --> 0 

} 

[結束更新]

原因[@Abhijith納加拉賈的答案之後開始更新]:我想初始化一個動態可視化(這需要滾動條 的ScrollPanel如下初始化在稍後的時間點),這樣看起來不錯,並且避免在稍後添加ScrollPanel。

+0

首先是滾動面板是從簡單的面板上,所以只有一個孩子可以添加,旁邊填補空白需要增加兒童的體形準確地滾動面板尺寸。希望這是你正在尋找的,如果不是,請更多地解釋它.. – Dipak 2013-03-16 04:49:27

回答

0

ScrollPanel sp = new ScrollPanel();

...

int innerWidth = sp.getOffsetWidth()- sp.getElement().getScrollWidth();

...

注:您可以使用上面的代碼只有當你的scrollPanell是附在屏幕上。換句話說,它應該被渲染。

+0

感謝您的回答。我嘗試瞭解決方案,但getOffsetWidth()和getOffsetHeight()始終爲0。滾動面板連接到dom。請在上面找到我的更新。 – Michael 2013-03-17 00:41:18

+0

附加到DOM沒有幫助...它應該呈現在屏幕上......一旦它應該呈現,那麼只有你可以調整它的寬度。 – 2013-03-17 05:13:53

+0

有沒有辦法強制渲染過程或檢查元素是否被渲染? – Michael 2013-03-17 05:38:39

0
DOM.setStyleAttribute(scrollpanel.getElement(), "maxHeight", mMainHeight + "px");;