GWT Relative Width

主宰稳场 提交于 2019-12-11 04:42:15

问题


I'm trying to make a scroll panel that has relative size parameters. But the ScrollPanel.setSize(String, String) function is impossible to work with if you have int values such as those returned by Window.getHeight.

When I try ScrollPanel.setSize("100%", "150px"); it doesn't change the height of the scroll panel and instead uses the default. Any help would be appreciated.


回答1:


According to the GWT doc for [ScrollPanel][1], they seem to be pretty strict about using the width in absolute and not relative CSS units. Thus the problem may be with the "100%" parameter.

[1]: http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/ScrollPanel.html#setSize(java.lang.String, java.lang.String)




回答2:


I'm not sure if it's possible to do with the height, but what worked for me with the width was to first set an arbitrary width, then get the element and set the the width property.

ScrollPanel myScrollPanel = new ScrollPanel();
myScrollPanel.setSize("2112px", "150px");   // Arbitrary width.
myScrollPanel.getElement().getStyle().setProperty("width", "100%");  // or "auto"

Hope this works for you (although you asked this 5 years ago, so you're probably not too worried about it anymore)!




回答3:


Copying my answer from here: How to use ScrollPanel with relative size

==================================================================

First, ScrollPanel is something not acting as other widget for reason I don't know why. Cannot set relative size (50%), and if I give it some style, it's lost somewhere and cannot be found from page.

My solution is to use a ResizeLayoutPanel. Andrei suggested using something ProvidesResize but requires the provide / require resize chain remain unbroken, which can be very tricky. I found this ResizeLayoutPanel "ProvidesResize to its one child, but does not RequiresResize", which is the perfect candidate for the root panel of my composite. Then, I just extend the ScrollPanel to resize itself in the "onResize" method whenever it's called by the parent ResizeLayoutPanel.

Still no answer to my first question: by ScrollPanel behave like this in the first place? I tried to find answer in its source code but was not successful (though I didn't spend enough time studying the source code).

public class My100PctScrollPanel extends ScrollPanel {
    @Override
    public void onResize() {
        // Window.alert("on resize"); 
        this.setWidth(this.getParent().getOffsetWidth()+"px");
        this.setHeight(this.getParent().getOffsetHeight()+"px");
        super.onResize();
    }
}

........

compositeRoot = new ResizeLayoutPanel();  

........
scrollPanel = new My100PctScrollPanel();
compositeRoot.clear();
compositeRoot.add(scrollPanel);


来源:https://stackoverflow.com/questions/1329849/gwt-relative-width

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!