Reputation: 699
I'm using GWT PopupPanel to display a popup above a button when user clicks it.
I am setting popup's position and showing it like so:
panel.setPopupPosition(leftPos, topPos);
panel.show();
However, when I inspect the popup's top value after it shows, I see that it is positions slightly lower than what I assigned it.
The issue may be that setPopupPosition changes the values that are passed in:
// Account for the difference between absolute position and the
// body's positioning context.
left -= Document.get().getBodyOffsetLeft();
top -= Document.get().getBodyOffsetTop();
How can I make sure the GWT PopupPanel's position is exactly the values I gave it? setPopupPosition()
seems to really be the only way to set the position, but it does some manipulation (which is unnecessary for my use case) to the positions I pass in.
Upvotes: 0
Views: 266
Reputation: 656
You can use direct access to popup's DOM element to adjust PopupPanel position. But it should be done after calling show() and before making popup visible. Otherwise, you'll may see some "jump" effects. Example:
PopupPanel popupPanel = new PopupPanel();
...
// this callback will be called after PopupPanel.show(), but before it is shown
popupPanel.setPopupPositionAndShow(new PositionCallback() {
@Override
public void setPosition(int offsetWidth, int offsetHeight) {
Style style = popupPanel.getElement().getStyle();
style.setLeft(100, Unit.PX);
style.setTop(100, Unit.PX);
}
});
Upvotes: 0