JDK-6431730 : Window.setRelativeTo Snaps to Wrong Top/Left Window Bound
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: linux
  • CPU: x86
  • Submitted: 2006-05-30
  • Updated: 2020-02-07
  • Resolved: 2020-02-07
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux plt04.cs.rice.edu 2.4.20-31.9smp #1 SMP Fri Jun 25 16:19:22 CDT 2004 i686
i686 i386 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
When a window is centered using Window.setRelativeTo, but after centering extends beyond the left or top edge of a screen, and that screen does not begin at coordinate (0, 0), then the window is moved to an incorrect location on the screen that DOES have 0 as coordinate for the edge.

Assume the user has two screens, screen A (0, 0, 1600, 1200) and screen B (1600, 0, 1600, 1200). If a window's position is set relative to another window on screen B, and after centering extends to the left of x coordinate 1600, then the window is moved to the x coordinate 0, which is the left edge of screen A, not the left edge of screen B.

The problem are the following lines (java.awt.Window:2149):

// Avoid being placed off the edge of the screen
if (dx+windowBounds.width > ss.x + ss.width) {
  dx = ss.x + ss.width - windowBounds.width;
}
if (dx < ss.x) dx = 0;
if (dy < ss.y) dy = 0;
                                                                                 
setLocation(dx, dy);

Instead of setting dx and dy to 0, they should be set to ss.x or ss.y, respectively.

Since setRelativeTo is used by most built-in dialogs of AWT and Swing, all of them are defective in multi-monitor environments!

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Place a window (called "first") close to the left edge of your second screen.
2) Create another window (called "second") that is much wider than the first window.
3) Call: second.setRelativeTo(first);


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The second window should have been moved to the left edge of the SECOND screen.
ACTUAL -
Since the second window extended beyond the left edge of the second screen, it has been moved to x = 0, which is the left edge of the FIRST screen.

REPRODUCIBILITY :
This bug can be reproduced always.

Comments
Cannot reproduce on the latest JDK.
07-02-2020

EVALUATION The changes suggested in the description are already implemented in Mustang as a part of the fix for 6177452. So I'm closing this bug as not reproducible.
02-06-2006