RFR: 4938801: The popup does not go when the component is removed. [v4]
Alexey Ivanov
aivanov at openjdk.org
Thu Jul 24 18:53:55 UTC 2025
On Thu, 24 Jul 2025 02:34:44 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> Issue is seen that a popup doesn't get closed when the component that invokes it, gets removed from the parent container.
>> This is because the JPopupMenu does not listen to its invoker liefecycle thereby behaving as a standalone entity after creation.
>> Fix is made to make sure popup listens to its invoker lifecycle by registering its PropertyChangeListener to the invoker and listens to the ["ancestor" property name ], https://github.com/openjdk/jdk/blob/441dbde2c3c915ffd916e39a5b4a91df5620d7f3/src/java.desktop/share/classes/javax/swing/JComponent.java#L4853-L4858 which will become null when removed, wherein we should dispose of the popup
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>
> typo
Changes requested by aivanov (Reviewer).
src/java.desktop/share/classes/javax/swing/JPopupMenu.java line 961:
> 959: popup.dispose();
> 960: popup = null;
> 961: }
This doesn't work for me on Windows.
Well, the test passes because `jpm.isVisible()` returns `false` since `popup` is set to `null`:
https://github.com/openjdk/jdk/blob/4e53a9d9dfe7a1ac7c3d7402e5ca3a3d3fcbb709/src/java.desktop/share/classes/javax/swing/JPopupMenu.java#L881-L883
But the popup itself remains on the screen.
-------------
PR Review: https://git.openjdk.org/jdk/pull/26407#pullrequestreview-3052849912
PR Review Comment: https://git.openjdk.org/jdk/pull/26407#discussion_r2229306411
More information about the client-libs-dev
mailing list