I saw in another thread that you could drop down and register listeners via native javascript, but that was not recommended. Looking at the javadocs, I didn’t see any other obvious way to do it, Component.Event did not have a subclass that seemed to handle this nor did I see any listener interface for it.
Am I missing something?
I’m asking because I’m using the overlays component, and if I position it over something that is scrollable, when you scroll, you get visual artifacts left on screen as a result of the scroll, I wanted to try listening for scroll events and repainting the screen to see if that would remedy the draw issue.
There’s no built-in way of listening for scroll events. You can try overriding a panel or a window setScrollTop/Left, and do something when those get called. You should also set the panel/window to immediate (setImmediate(true)) to get scroll updates right after the scroll is done.
Note also, that since this will require a server round-trip, the update for the overlay will not be instantaneous because of the request lag.
I’m wondering the same thing, but on the client-side.
So, I tried to use:
Event.addNativePreviewHandler but without a luck. It never gets any events.
Any experience with this one? I’ve seen this in use with mouse events, but for
Event.ONSCROLL it seems not to work.
A bonus question: Any way to listen layout resize (client or server side would do)?
The problem is that scroll events don’t bubble/propagate up the dom tree, so the preview handler (which, as I believe, is in the root/body of the page in GWT) never gets the event. You an only listen for scroll events on the exact element they occur in.
That’s perfectly doable. Just implement the
ContainerResizedListener interface and the
iLayout method. That method will get called every time the parent layout size changes.