gpt4 book ai didi

GWT:PopupPanel setPopupPositionAndShow() 提供了错误的 offsetWidth 和 offsetHeight

转载 作者:行者123 更新时间:2023-12-04 22:21:44 28 4
gpt4 key购买 nike

我在 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);

}
}
}

}

问题是 offsetWidthoffsetHeight 总是 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>

最佳答案

为了解决这个问题,我遵循了 PopupPanelsetPopupPositionAndShow() 使用的步骤,但我将定位步骤设为延迟命令。我的代码没有扩展 PopupPanel,因此 popupPanel 变量:

popupPanel.setVisible(false);
popupPanel.show();

// Pausing until the event loop is clear appears to give the browser
// sufficient time to apply CSS styling. We use the popup's offset
// width and height to calculate the display position, but those
// dimensions are not accurate until styling has been applied.
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
yourMethodToSetPositionGoesHere(popupPanel);
popupPanel.setVisible(true);
}
});

关于GWT:PopupPanel setPopupPositionAndShow() 提供了错误的 offsetWidth 和 offsetHeight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8054360/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com