2
如何將彈出窗口定位在GWT中鼠標單擊的位置。我嘗試使用getX和getY來設置彈性,並將Popup設置爲該位置,但這不起作用。定位彈出窗口GWT
如何將彈出窗口定位在GWT中鼠標單擊的位置。我嘗試使用getX和getY來設置彈性,並將Popup設置爲該位置,但這不起作用。定位彈出窗口GWT
簡單的例子:
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);
}
});
注:
left = event.getRelativeX(myContextElem);
等)sinkEvents(Event.ONMOUSEDOWN)
。