File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
src/java.desktop/share/classes/javax/swing Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments