Getting notified on a window being grabbed and moved / resized

Kirill Grouchnikov kirill.grouchnikov at gmail.com
Tue Jun 28 15:19:02 UTC 2022


Is there a public / supported way to get notified when an OS-decorated
window (native title pane from macOS, Windows, etc) is moved around or
resized by the user grabbing the title bar or the border?

I want to get notified on that process starting so that I can hide all the
popups. What I see is that at [1] this is how Swing's popup menu registers
itself to get notified on window grabbing. Note that it's using internal,
undocumented and inaccessible event mask. Then at [2] it gets notified that
the window has been ungrabbed so that it can hide itself. Again, internal
and inaccessible event class. And there's also APIs at [3] to grab / ungrab
windows to have the whole process rolling.

Are there alternatives to these internal APIs that have been exposed as
part of hiding the implementation details?

The only thing I could find so far is adding a component listener to the
frame, but "componentMoved" is called with a noticeable lag, hundreds of
milliseconds after the window has started moving.

[1]
https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java#L790
[2]
https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java#L861
[3]
https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/awt/SunToolkit.java#L1641
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20220628/bdf78bbf/attachment.htm>


More information about the client-libs-dev mailing list