JDK-8124074 : PopupWindow reports incorrect width and height
  • Type: Bug
  • Component: javafx
  • Sub-Component: scenegraph
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-04-20
  • Updated: 2015-06-17
  • Resolved: 2013-09-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Fixed
Related Reports
Blocks :  
Blocks :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
I've noticed that CustomColorDialog appears shifted from the right edge of ColorPalette PopupWindow. In fact, my investigation shows that PopupWindow x, y, width, height rectangle is shifted to the right and bottom from the actual position. 

To illustrate that I've changed ColorPalette code so when you click on Custom Color link it opens four stages each is expected to be adjacent to Palette window. In fact, only top and left are adjucent while bottom and right are at a distance. See attached screenshot.

The problem is caused by PopupWindow.syncWithRootBounds() method which does some "black" magic behind the scenes:

        // update popup dimensions
        setWidth(layoutBounds.getMaxX() - layoutBounds.getMinX());
        setHeight(layoutBounds.getMaxY() - layoutBounds.getMinY());
        // update transform
        rootNode.setTranslateX(-layoutBounds.getMinX());
        rootNode.setTranslateY(-layoutBounds.getMinY());
        if (alignWithContentOrigin) {
            // update window position
            setWindowTranslate(layoutBounds.getMinX(), layoutBounds.getMinY());
            ...
        }

The root cause is that root node has shadow and the shadow contributes to width and height of the PopupWindow but doesn't affect its x and y.
Comments
Changeset: 610ea3cbc099 Author: Lubomir Nerad <lubomir.nerad@oracle.com> Date: Thu Sep 12 10:09:43 2013 +0200 URL: http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/610ea3cbc099 Description: Fix for RT-29891: PopupWindow reports incorrect width and height Unit tests: javafx.stage.PopupTest.testAnchorPositioning javafx.stage.PopupTest.testAnchorKeepsPositionOnContentChange
19-02-2015

New proposal for popup positioning (for PopupWindow class): replace: public void show(Node ownerNode, double screenX, double screenY); public void show(Window ownerWindow, double screenX, double screenY); with: public void show(Node ownerNode, double anchorX, double anchorY); public void show(Window ownerWindow, double anchorX, double anchorY); add anchorX and anchorY read only properties add setAnchorX and setAnchorY methods add anchorLocation property of ObjectProperty<AnchorLocation> type with WINDOW_TOP_LEFT default value add AnchorLocation enum as a nested class to PopupWindow with the following constants: WINDOW_TOP_LEFT, WINDOW_TOP_RIGHT, WINDOW_BOTTOM_LEFT, WINDOW_BOTTOM_RIGHT, CONTENT_TOP_LEFT, CONTENT_TOP_RIGHT, CONTENT_BOTTOM_LEFT, CONTENT_BOTTOM_RIGHT More details and javadocs on: http://tatry.cz.oracle.com/review/r/2203/diff/#5
19-08-2013

After an internal discussion we decided to revert the part of RT-28775 fix which changes the interpretation of x and y properties of Popup window.
19-08-2013

Reassigning to Richard to get his opinion. He agreed to offset the x, y coordinates for Popup windows.
28-05-2013

In Popup code, we don't know where the shadow lies nor which node in the scenegraph caused it. Actually it doesn't matter whether the "alignment" offset was caused by shadow or any other content (it is defined generally). Also if the offset is used to compensate for shadow, we can't adjust the width or height, because we don't know how large it is on the right / bottom side.
21-05-2013

I believe for the case when window x and y point to the upper-left corner of the node that has shadow, width and height should contain size of that node. Otherwise it is totally inconsistent. Richard, what do you think?
20-05-2013

This is result of PopupWindow reference point change requested in RT-28775. External windows can be correctly placed if the fixed Node.localToScreen (RT-29728) conversions are used.
24-04-2013

Probably this one is duplicate of RT-29728
20-04-2013

The problem is worsen by the fact the root node is Group so any layout bounds information is lost. I don't see any clear workaround.
20-04-2013

layoutBounds here is BoundingBox [minX:-12.0, minY:-4.0, minZ:0.0, width:241.0, height:255.0, depth:0.0, maxX:229.0, maxY:251.0, maxZ:0.0] which results in the following window width and height: window.getWidth = 241, window.getHeight = 255
20-04-2013