Obtaining the click position of the underlying widget from an overlay widget

22 views
Skip to first unread message

Alexander Orlov

unread,
Aug 16, 2011, 8:26:33 AM8/16/11
to google-we...@googlegroups.com
I have something like

<g:ScrollPanel>
    </g:FocusPanel>
<!-- a few FocusPanels -->
</g:ScrollPanel>

The FocusPanel is attached to a random place within the ScrollPanel. Now I want to get the position of the place where the user places his click. I've tried the following 

focusPanel.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
              System.out.println(event.getClientX());
                System.out.println(event.getX());
                System.out.println(event.getRelativeX(event.getRelativeElement().getOffsetLeft()));
                System.out.println(event.getRelativeElement().getOffsetLeft());
                System.out.println(event.getRelativeElement().getOffsetWidth());
                System.out.println(event.getRelativeElement().getOffsetHeight());
                System.out.println(event.getRelativeElement().getOffsetTop());
                System.out.println(event.getScreenX());
            }
}

...but I always get the same values, no matter where I place my click on the focusPanel.

Ivan Pulleyn

unread,
Aug 16, 2011, 8:38:54 AM8/16/11
to google-we...@googlegroups.com

I believe you want this:

int x = event.getRelativeX(event.getRelativeElement());
int y = event.getRelativeY(event.getRelativeElement());


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/J4cH7AUDKBcJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Alexander Orlov

unread,
Aug 16, 2011, 8:57:07 AM8/16/11
to google-we...@googlegroups.com
On Tue, Aug 16, 2011 at 2:38 PM, Ivan Pulleyn <ivan.p...@gmail.com> wrote:

I believe you want this:

int x = event.getRelativeX(event.getRelativeElement());
int y = event.getRelativeY(event.getRelativeElement());

Unfortunately not, I always get:

event.x = -266
event.y = -133

...no matter where on the FocusPanel I click, the value remain static. When I click on another FocusPanel the values change but reamin static within the same FocusPanel.



--
www.loxal.net
Mobile: +49 176 4440-3969
Rablstr. 12 • 81669 Munich • Germany

Reply all
Reply to author
Forward
0 new messages