RFR: 8370652: Control and ScrollPaneSkin should snap computed width/height values to prevent scrollbars appearing due to rounding errors
John Hendrikx
jhendrikx at openjdk.org
Tue Oct 28 07:20:23 UTC 2025
On Mon, 27 Oct 2025 21:48:44 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
> Thank you, @hjohn !
>
> I think this is the right approach; the chance of regression is likely to be low, despite the change impacting all the controls.
>
> A side note: as a rule, we could probably snap just the final result, even considering small floating point errors that accumulate in the intermediate computation. For example, let's estimate a rather unlikely case of a table with 1000 columns of 1000 pixels each. `Math.ulp(1000.0) = 1.1368683772161603E-13`, so the possible error multiplied by 1000 is still < `2E-10`. As long as we snap the result (or when a comparison is performed), we should be ok.
I considered doing that in `ScrollPaneSkin` but I prefer to find the root cause of these problems. The fix in `Control` can fix other problems as well, and is highly unlikely to cause new problems. If anything it shows once again how hard it is to reason about float values, but at least we now know that a resnap of the final value is **always** required. This will help when reviewing layout code or when fixing issues.
We could consider a broad review of code that works with snapped values, and make sure values which use snapping are always resnapped before returning them.
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1948#issuecomment-3454947142
More information about the openjfx-dev
mailing list