This panel keeps getting position: absolute applied. How can I stop it?
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 po开发者_运维知识库sition: 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.
It seems to be a bug in GWT:
http://code.google.com/p/google-web-toolkit/issues/detail?id=5251
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 removing myChildAbsolutePanel
from its parent AbsolutePanel.
Far from being beautiful - but works for me.
精彩评论