GWT 相对宽度
我正在尝试制作一个具有相对尺寸参数的滚动面板。但是,如果您有诸如 Window.getHeight
返回的 int 值,则 ScrollPanel.setSize(String, String)
函数将无法使用。
当我尝试 ScrollPanel.setSize("100%", "150px");
它不会更改滚动面板的高度,而是使用默认值。任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 [ScrollPanel][1] 的 GWT 文档,他们似乎对使用绝对而不是相对 CSS 单位的宽度非常严格。
因此问题可能出在“100%”参数上。
[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)
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)
我不确定是否可以处理高度,但对我来说宽度的工作是首先设置任意宽度,然后获取元素并设置 width 属性。
希望这对您有用(尽管您 5 年前就问过这个问题,所以您可能不再太担心了)!
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.
Hope this works for you (although you asked this 5 years ago, so you're probably not too worried about it anymore)!
从这里复制我的答案:如何使用 ScrollPanel相对大小
============================================= =======================
首先,ScrollPanel 不能充当其他小部件,因为我不知道为什么。无法设置相对大小(50%),如果我给它一些样式,它就会丢失在某处并且无法从页面中找到。
我的解决方案是使用 ResizeLayoutPanel。 Andrei 建议使用 ProvidesResize,但要求提供/要求调整大小链保持完整,这可能非常棘手。我发现这个 ResizeLayoutPanel“为其一个子项提供Resize,但不要求Resize”,它是我的复合材料的根面板的完美候选者。然后,我只需扩展 ScrollPanel,以便在父 ResizeLayoutPanel 调用“onResize”方法时调整自身大小。
我的第一个问题仍然没有答案:ScrollPanel 的行为首先是这样的吗?我试图在其源代码中找到答案,但没有成功(尽管我没有花足够的时间研究源代码)。
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).