RFR: 8228363: ContextMenu.show with side=TOP does not work the first time in the presence of CSS

Robert Lichtenberger rlichten at openjdk.java.net
Fri Jan 22 11:04:48 UTC 2021

On Fri, 22 Jan 2021 10:53:00 GMT, Robert Lichtenberger <rlichten at openjdk.org> wrote:

>> modules/javafx.controls/src/main/java/javafx/scene/control/ContextMenu.java line 241:
>>> 239:      * the {@code ContextMenu} such that its top-left (0,0) position would be attached
>>> 240:      * to the top-right position of the anchor.
>>> 241:      * <p>
>> I think it is worth adding a short replacement for this, explaining how the side parameter and delta values affect the location of the popup.
> While trying to come up with a good documentation I've detected a real change in behaviour in connection with the NodeOrientation of the anchor node.
> Although this has never been documented, when NodeOrientation.RIGHT_TO_LEFT is set, the context menu was right-aligned for Side=TOP and Side=BOTTOM. 
> Since I assume we don't want to change this behaviour I would now document it and adapt my patch accordingly. I've already written a test case like this:
>     @Test public void test_position_withOrientation() throws InterruptedException {
>         ContextMenu cm = createContextMenu(false);
>         anchorBtn.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
>         cm.show(anchorBtn, Side.TOP, 0, 0);
>         Bounds anchorBounds = anchorBtn.localToScreen(anchorBtn.getLayoutBounds());
>         Node cmNode = cm.getScene().getRoot();
>         Bounds cmBounds = cm.getScene().getRoot().localToScreen(cmNode.getLayoutBounds());
>         assertEquals(anchorBounds.getMaxX(), cmBounds.getMaxX(), 0.0);
>         assertEquals(anchorBounds.getMinY(), cmBounds.getMaxY(), 0.0);
>         anchorBtn.setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT);
>     }
> which passes with the old implementation but (currently) fails with the new implementation.

Oh wow. Further experimentation has shown, that if NodeOrientation.RIGHT_TO_LEFT is used on the anchor, then Side.LEFT used to make the menu appear on the **right** hand side and Side.RIGHT used to make the menu appear on the **left** hand side of the button, which really suprises me, since I didn't expect the side parameter to be relative.


PR: https://git.openjdk.java.net/jfx/pull/383

More information about the openjfx-dev mailing list