我已经在GWT中编写了自己的PopupPanel
。我想显示相对于其他窗口小部件的弹出窗口。我对该类的实现如下所示:
public class Popover extends PopupPanel implements PositionCallback {
private static final Binder binder = GWT.create(Binder.class);
private UIObject relative;
interface Binder extends UiBinder<Widget, Popover> {
}
public Popover() {
setWidget(binder.createAndBindUi(this));
setStylePrimaryName("popover");
}
public void show(UIObject relative) {
this.relative = relative;
setPopupPositionAndShow(this);
}
public void setPosition(int offsetWidth, int offsetHeight) {
if (relative != null) {
int left = relative.getAbsoluteLeft();
int top = relative.getAbsoluteTop();
int width = relative.getOffsetWidth();
int height = relative.getOffsetHeight();
int topCenter = top + height / 2 - offsetHeight / 2;
if (offsetWidth < left) {
setPopupPosition(left - offsetWidth, topCenter);
} else {
setPopupPosition(left + width, topCenter);
}
}
}
}
问题是
offsetWidth
和offsetHeight
始终是10
?我的
Popover.ui.xml
如下所示:<g:FlowPanel stylePrimaryName="popover">
<g:FlowPanel stylePrimaryName="arrow" />
<g:FlowPanel stylePrimaryName="inner">
<g:Label stylePrimaryName="title" text="New Label" />
<g:FlowPanel stylePrimaryName="content">
<g:Label text="Hallo" />
</g:FlowPanel>
</g:FlowPanel>
</g:FlowPanel>
最佳答案
getOffsetWidth()
和getOffsetHeight()
仅在完全构建DOM且要获取其值的容器可见且已附加的情况下起作用。
为什么不使用showRelativeTo()
的PopupPanel
功能?
popup.showRelativeTo(SomeWidget);
关于gwt - GWT:PopupPanel setPopupPositionAndShow()传递错误的offsetWidth和offsetHeight,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8054360/