On Mon, 21 Jul 2025 02:16:27 GMT, Prasanta Sadhukhan <psadhuk...@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

src/java.desktop/share/classes/javax/swing/JPopupMenu.java line 947:

> 945:             public void propertyChange(PropertyChangeEvent e) {
> 946:                 String propertyName = e.getPropertyName();
> 947:                 if (propertyName == "ancestor") {

Just curious, where is the `ancestor` property added to the listener list? I 
have tried tracking this down to follow the logic, and I could not find it, nor 
can I find it under the bound properties list on javadoc.

Testing seems to be ok AFAIK but I wanted to trace the code to double-check.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26407#discussion_r2219703042

Reply via email to