GWT:PopupPanel setPopupPositionAndShow() 提供错误的 offsetWidth 和 offsetHeight
我用 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>
I have written my own PopupPanel
in GWT. I want to show the popup relative to an other widget. My implementation of the class looks like the following:
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);
}
}
}
}
The problem is that offsetWidth
and offsetHeight
is always 10
?
My Popover.ui.xml
looks like the following:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了解决这个问题,我遵循了
PopupPanel
的setPopupPositionAndShow()
使用的步骤,但我将定位步骤设置为延迟命令。我的代码没有扩展PopupPanel
,因此popupPanel
变量:To solve this issue, I followed the steps used by
PopupPanel
'ssetPopupPositionAndShow()
, but I made the positioning step a deferred command. My code didn't extendPopupPanel
, hence thepopupPanel
variable:getOffsetWidth()
和getOffsetHeight()
仅当 DOM 完全构建并且您要获取其值的容器可见且附加时才有效。为什么不使用
PopupPanel
的showRelativeTo()
函数?getOffsetWidth()
andgetOffsetHeight()
only work if the DOM is fully constructed and the container for which you want to get the value is visible and attached.Why don't you use the
showRelativeTo()
function of thePopupPanel
?