RFR: 8370498: Improve how Node detects whether a layout property change requires a new layout pass [v2]

John Hendrikx jhendrikx at openjdk.org
Thu Oct 23 17:10:15 UTC 2025


On Thu, 23 Oct 2025 16:55:32 GMT, John Hendrikx <jhendrikx at openjdk.org> wrote:

>> This new check is much more accurate to detect whether a parent is currently laying out its children. The previous code almost never worked, resulting in additional unnecessary layouts.
>
> John Hendrikx has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix ToolBarSkinTest
>   
>   Reusing a toolbar as part of several scenes, in combination with the StubToolkit that doesn't handle pulses makes this test fail with the relayout detection fix.

`ToolBarSkinTest` failed due to a combination of using the StubToolkit (which doesn't run pulses) and the reuse of the `ToolBar` node in several different stages (which somehow is allowed without warning).  I've modified the test so that it still detects the original problem that it intended to fix (I reverted the fix for https://bugs.openjdk.org/browse/JDK-8364049 and checked that the rewritten test still fails without the fix).

The rewritten test works without problem with this fix, and also without this fix.

The reason why the test failed is because the size cache in `Parent` was re-used between tests. Before this PR, the test would do this:
- Creates a Stage with a reusable ToolBar
- Shows the stage (this triggers a layout, it's not because of a pulse as `StubToolKit` doesn't run those)
- Lots of layout occurs, including an attempt to start a 2nd layout pass (which `StubToolKit` won't run)
- The triggering of the 2nd layout pass however would clear the size cache in preparation for a next layout pass
- The stage is hidden, and the 2nd layout pass never runs
- A new Stage is created with the reused ToolBar, and luckily its size cache was cleared so it had to redo the calculations with the new render scale.

In the version with the fix in this PR applied, no 2nd layout pass is triggered, and thus the size cache was not cleared, and the reuse of the ToolBar node would then happily use size values belonging to the old render scale.

I also tested `ToolBar` on my own system (with a real program), and dragged the window from a monitor with 150% to 125% scale, and  the tool bar looked okay.

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1945#issuecomment-3438146066


More information about the openjfx-dev mailing list