On Fri, 25 Jul 2025 07:31:42 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
>
> Prasanta Sadhukhan has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Use setVisible(false) instead of dispose, update test

I still think [using events and 
latches](https://github.com/openjdk/jdk/pull/26407#discussion_r2219783806) 
would be better.

> Perhaps, a better version of the test would remove the component when the 
> event from the popup menu that it's now displayed is received. If the popup 
> is hidden as the result of component removal, another event should be 
> received. Thus, the test would depend on the events and latches instead of on 
> the delays.

Thus, I suggest this version of the test: 
[`TestPopupInvoker.java`](https://github.com/openjdk/jdk/blob/63a511ae18ac145233bb9aa976f77b7d0c607ea3/test/jdk/javax/swing/JPopupMenu/TestPopupInvoker.java).

It is this version of the test that help me find [the bug in the 
implementation](https://github.com/openjdk/jdk/pull/26407#discussion_r2229306411)
 where hiding the popup menu didn't send events. Therefore, this version is 
more valuable: *it ensures the correct popup menu events are sent* when the 
invoker is removed and, as the result, the popup gets dismissed.

The [diff the most recent 
version](https://github.com/openjdk/jdk/commit/63a511ae18ac145233bb9aa976f77b7d0c607ea3)
 in this PR.

The updated version of the test is quicker, a loop of 10 iterations takes about 
1 minute vs 1:11, that is around 10 seconds faster, which means each iteration 
completes around 1 second quicker.

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

PR Comment: https://git.openjdk.org/jdk/pull/26407#issuecomment-3128559326

Reply via email to