JDK-6702119 : window.getLocationOnScreen() returns a wrong value when it is displayed to a hidden component
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2008-05-14
  • Updated: 2011-01-19
  • Resolved: 2010-10-04
Related Reports
Relates :  
Description
I have a frame which contains two button. when i click on the first button, the second button gets hidden & i am displaying a window location according to setLocationRelativeTo of the hidden component. when i do this the window is displayed to the center of the screen, then i take the window location & comparing with the actual center of the screen , when i do the return value of the window location is wrong. 

This scenario pass in jdk6.0 b104 build, it even pass in 6u10_b23 also. but fails in jdk7. I tested from jdk7 b23 to jdk7 pit build 27.

Step to reproduce:
--------------------
1) Run the attached testcase.
2) Click on the first button. Observe that second button gets hidden & a window with yellow color is displayed to the center of the screen. Observe on the screen value of the console . If you see the failed message , then the bug is reproduced.
Attached the testcase.

Comments
EVALUATION After the fix for 6232687, hidden and null components passed to Window.setLocationRelativeTo() are treated differently. The current behavior conforms to the specification, closing this bug as not a defect.
04-10-2010

EVALUATION Window.setLocationRelativeTo(comp) places the window incorrectly when the given component is hidden. The snippet from the setLocationRelativeTo method calculates the location: ======================================================================= } else if (!c.isShowing()) { gc = componentWindow.getGraphicsConfiguration(); gcBounds = gc.getBounds(); dx = gcBounds.x + (gcBounds.width - windowSize.width) / 2; dy = gcBounds.y + (gcBounds.height - windowSize.height) / 2; } ... ======================================================================= This code places the window in the center of the screen to which the invisible component actually belongs. However, the code doesn't take into account the insets of the screen. The problem was introduced by the fix for 6232687, the fix is to treat the hidden component separately from the null component: - null - the location is GE.getCenterPoint(), - invisible component - the location is center of the screen the invisible component belongs to.
04-06-2008