Skip to content

Commit 23ed890

Browse files
Sergei TachenovAlexey Ushakov
authored andcommitted
6415065: Submenu is shown on wrong screen in multiple monitor environment
Reviewed-by: prr
1 parent ca47f5f commit 23ed890

File tree

1 file changed

+17
-0
lines changed
  • src/java.desktop/share/classes/javax/swing

1 file changed

+17
-0
lines changed

src/java.desktop/share/classes/javax/swing/JMenu.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,23 @@ protected Point getPopupMenuOrigin() {
478478
y = 0 - yOffset - pmSize.height; // Otherwise drop 'up'
479479
}
480480
}
481+
// Note that the position may be later adjusted to fit the menu into the screen if possible.
482+
// However, the code that does it (JPopupMenu.adjustPopupLocationToFitScreen) has no idea which screen
483+
// to fit into, and determines it by the position calculated here, so we need to make sure it's on
484+
// the correct screen, otherwise the menu may appear on the wrong screen (JDK-6415065).
485+
// (Both x and y are relative to the JMenu position here, that's why we need these +-position.x/y here.)
486+
if (position.y + y < screenBounds.y) { // Above the current screen?
487+
y = screenBounds.y - position.y; // The top of the screen relative to this JMenu.
488+
}
489+
if (position.y + y >= screenBounds.y + screenBounds.height) { // Below the current screen?
490+
y = screenBounds.y + screenBounds.height - 1 - position.y; // The bottom of the screen...
491+
}
492+
if (position.x + x < screenBounds.x) { // To the left of the current screen?
493+
x = screenBounds.x - position.x; // The left edge of the screen...
494+
}
495+
if (position.x + x >= screenBounds.x + screenBounds.width) { // To the right of the current screen?
496+
x = screenBounds.x + screenBounds.width - 1 - position.x; // The right edge of the screen...
497+
}
481498
return new Point(x,y);
482499
}
483500

0 commit comments

Comments
 (0)