Global Warrior
Global Warrior

Reputation: 5130

Positioning Popup GWT

How Can i position Popup at the mouse clicked position in GWT. I tried using the getX, and getY on the flextable and set the Popup to that position but that isn't working.

Upvotes: 2

Views: 783

Answers (1)

Chris Lercher
Chris Lercher

Reputation: 37788

Quick example:

final RootLayoutPanel rootLayoutPanel = RootLayoutPanel.get();

final FocusPanel focusPanel = new FocusPanel();

/* just to make the clickable area visible */
focusPanel.getElement().getStyle().setBackgroundColor("red");

rootLayoutPanel.add(focusPanel);


final PopupPanel popupPanel = new PopupPanel();
popupPanel.add(new Label("Popup"));
popupPanel.show();

focusPanel.addClickHandler(new ClickHandler() {

  @Override
  public void onClick(final ClickEvent event) {
    final int left = event.getClientX();
    final int top = event.getClientY();

    popupPanel.setPopupPosition(left, top);
  }
});

Notes:

  • Make sure to show the PopupPanel after adding the focusPanel, otherwise it will be behind the focusPanel.
  • I'm using the RootLayoutPanel here, but you could also work relative to a different element (use left = event.getRelativeX(myContextElem); etc.)
  • If you don't want to use a FocusPanel (which has ClickHandlers), you could alternatively use a MouseDownHandler, but in that case you then need to call sinkEvents(Event.ONMOUSEDOWN).

Upvotes: 2

Related Questions