RFR: 4938801: The popup does not go when the component is removed [v6]
Jeremy Wood
duke at openjdk.org
Tue Jul 29 22:38:57 UTC 2025
On Tue, 29 Jul 2025 11:56:49 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:
>
> Use named property listener, update test
src/java.desktop/share/classes/javax/swing/JPopupMenu.java line 1427:
> 1425: indexCounter++;
> 1426: }
> 1427: }
This may be a naive question: is the lambda we use for `propListener` Serializable?
(If so: great. If not: won't we get inconsistent results if we're working with a deserialized copy of a JPopupMenu? The original will have a non-null `propListener` field, and the copy will have a null `propListener`? Or am I missing something?)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26407#discussion_r2241147333
More information about the client-libs-dev
mailing list