我想知道是否有可能获得
的内部大小com.google.gwt.user.client.ui.ScrollPanel
GWT中的对象?我想创建一个ScrollPanel的子项,它完全适合空白区域,而不需要激活滚动条。 ScrollPanel初始化如下:
[@Abhijith Nagaraja回答后开始更新]
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
}
[结束更新]
原因:我想初始化一个动态可视化(以后需要滚动条),这样看起来不错,以后可以避免添加ScrollPanel。
答案 0 :(得分:0)
ScrollPanel sp = new ScrollPanel();
...
int innerWidth = sp.
getOffsetWidth() - sp.getElement().
getScrollWidth() ;
...
注意: 仅当您的scrollPanell附加到屏幕时,才能使用上述代码。换句话说,它应该被渲染。
答案 1 :(得分:0)
DOM.setStyleAttribute(scrollpanel.getElement(), "maxHeight", mMainHeight + "px");;