On Thu, 10 Aug 2023 00:04:52 GMT, Sergey Bylokhov <[email protected]> wrote:

>> Hello!
>> 
>> I'm a member of the UI team in JetBrains IntelliJ department, and we have 
>> this bug with popup menus being shown on the wrong monitor in multi-monitor 
>> environments:
>> 
>> https://youtrack.jetbrains.com/issue/JBR-5824/Dual-monitor-bug-on-the-context-menu
>> 
>> I managed to track it down to this JDK bug:
>> 
>> https://bugs.openjdk.org/browse/JDK-6415065
>> 
>> I've described the cause and the fix in the commit message, but in short, 
>> what happens here is that `JMenu.getPopupMenuOrigin` sometimes returns 
>> coordinates outside (usually above) of the current screen, and later 
>> `JPopupMenu.adjustPopupLocationToFitScreen` uses those coordinates to fit 
>> the entire popup menu into the screen, which goes wrong because at that 
>> point it's no longer known which screen the menu was initially invoked on.
>> 
>> I've fixed this by making sure the Y coordinate is still within the correct 
>> screen when it's returned from `JMenu.getPopupMenuOrigin`.
>
> src/java.desktop/share/classes/javax/swing/JMenu.java line 489:
> 
>> 487:         }
>> 488:         if (position.y + y >= screenBounds.y + screenBounds.height) { 
>> // Below the current screen?
>> 489:             y = screenBounds.y + screenBounds.height - 1 - position.y; 
>> // Fit into the screen, relative to our origin.
> 
> why only the y coordinate is checked? Can we implement it for x as well for 
> symmetry?

A good idea. I was actually thinking about it after I had submitted this. Even 
though I've never encountered any issues with the X coordinate, I think it's 
still possible in theory in some unusual circumstances. Anyway, an extra check 
definitely won't hurt. Will do.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15185#discussion_r1289553429

Reply via email to