该面板不断获得位置:绝对应用。我怎样才能阻止它?
我正在使用 AbsolutePanel 来做一些拖放之类的事情。我将子窗口小部件添加到 AbsolutePanel,然后使用absolutePanel.setWidgetPosition 设置它们的位置。
但我不断收到此错误:
java.lang.IllegalStateException:com.google.gwt.user.client.ui.AbsolutePanel 缺少 CSS 'position:{relative,absolute,fixed}'
堆栈跟踪直接指向 setWidgetPosition 调用。
但!我不仅已经调用了absolutePanel.getElement.getStyle().setPosition(Position.RELATIVE),而且还应用了带有position:relative 属性的样式名称。当我使用 FireBug 检查该元素时,它有一个带有“position:absolute”的样式属性,大概会覆盖其他所有内容。
我怎样才能摆脱这个警告?
实际的行为似乎工作正常,但也许我错过了一些东西。
I'm using an AbsolutePanel to do some drag-and-drop kind of stuff. I add child Widgets to the AbsolutePanel, and then use absolutePanel.setWidgetPosition to set their position.
But I keep getting this error:
java.lang.IllegalStateException: com.google.gwt.user.client.ui.AbsolutePanel is missing CSS 'position:{relative,absolute,fixed}'
the stack trace points right to the setWidgetPosition call.
BUT! Not only have I already called absolutePanel.getElement.getStyle().setPosition(Position.RELATIVE), I have also applied a style name with a position: relative attribute. When I inspect the element with FireBug, it has a style attribute with "position: absolute" right in it, presumably overriding everything else.
How can I get rid of this warning?
The actual behavior seems to be working fine, but maybe I'm missing something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎是 GWT 中的一个错误:
http:// code.google.com/p/google-web-toolkit/issues/detail?id=5251
It seems to be a bug in GWT:
http://code.google.com/p/google-web-toolkit/issues/detail?id=5251
不确定这个错误是否真的得到修复,因为我在 GWT 2.6.0 中仍然遇到这个问题。
查看 AbsolutePanel 的代码,我注意到当子元素从 AbsolutePanel 中删除时,它会清空子元素的位置属性值。
当子项重新添加到 AbsolutePanel 时,位置属性仍为空。
如果重新添加的子级本身是 AbsolutePanel,则这是有问题的,因为在这种情况下,在子 AbsolutePanel 上调用 setWidgetPosition 时会发生 IllegalStateException 异常。
当你在做一些拖拽时删除通常与添加/删除小部件一起出现的内容,我认为这就是发生的事情。
解决方法:
从其父 AbsolutePanel 中删除
myChildAbsolutePanel
后立即调用myChildAbsolutePanel.getElement().getStyle().setProperty("position", "relative")
。远非美丽 - 但对我有用。
Not sure, if this bug actually got fixed as I'm still experiencing this problem with GWT 2.6.0.
Looking into the code of AbsolutePanel I noticed that it empties the value of the position attibute of a child element when it is removed from the AbsolutePanel.
When the child is re-added to the AbsolutePanel the position attribute remains empty.
This is problematic, if the re-added child itself is an AbsolutePanel, because in this case an IllegalStateException exception occurs when setWidgetPosition is called on the child AbsolutePanel.
As you were doing some drag & drop stuff which usually goes along with adding / removing widgets I assume this is what has happened.
Workaround:
Call
myChildAbsolutePanel.getElement().getStyle().setProperty("position", "relative")
right after removingmyChildAbsolutePanel
from its parent AbsolutePanel.Far from being beautiful - but works for me.