Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT - popup position

Tags:

gwt

How Do I position a popup in gwt to at mouse position. I have a huge flextable and the flextable contains button. If a button is pressed then a popup appears with some data, but the popup always appears at the top of the page. if a user is at the bottom of the table, then the popup will be out of the view and they are unable to see it?

How to I get the x and y co-ordinates of the mouse position?

like image 574
sap Avatar asked Jun 22 '11 14:06

sap


1 Answers

The showRelativeTo method of the PopupPanel class works well in my use-case.

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;

public class CommentPanelPopupImage extends Image {
    public CommentPanelPopupImage(final int tableId, final String referenceId, final String title) {
        super("external-link-ltr-icon.png");
        setTitle("Click to see comments");
        final CommentPanelPopupImage commentPanelPopupImage = this;
        addClickHandler(new ClickHandler() {

            public void onClick(final ClickEvent event) {
                final CommentPopupPanel popup = new CommentPopupPanel(tableId, referenceId, title);
                popup.setPopupPositionAndShow(new PositionCallback() {

                    public void setPosition(int offsetWidth, int offsetHeight) {
                        popup.showRelativeTo(commentPanelPopupImage);
                    }
                });
            }
        });
    }
}
like image 121
PLA Avatar answered Sep 25 '22 22:09

PLA