RFR: 8222210: JFXPanel popups open at wrong coordinates when using multiple hidpi monitors [v2]

Kevin Rushforth kcr at openjdk.org
Fri Oct 28 16:25:28 UTC 2022


On Fri, 28 Oct 2022 16:13:31 GMT, Andy Goryachev <angorya at openjdk.org> wrote:

>> I believe these values should be int in the first place. Otherwise, we have issues in JavaFX where we process them as ints.
>> About negative coordinates: yes, that works. Is the question about using Dimension2D (width/height) for something that is actually a Point2D? We can use a Point2D here as well, but that class seems to have a bit more overhead than Dimension2D for this goal -- but I'm open to change it to Point2D.
>
> No, what I meant is this:
> 
>  System.out.println("(int)-1.9999=" + (int)-1.9999 + " (int)Math.round(-1.9999)=" + (int)(Math.round(-1.9999)));
> prints
> (int)-1.9999=-1 (int)Math.round(-1.9999)=-2
> 
> 
> i.e. typecast to int is equivalent to Math.ceil for negative values and Math.floor for positive.  We probably should use Math.round().
> 
> This code should be better tested on Windows with
> a) second monitor positioned to the left of the main one, making its coordinates negative
> b) using fractional HiDPI scaling which is only available on Windows it seems
> 
> And yes, I did not see Dimension2D - we probably should remove confusion and use Point2D (why does it have more overhead?)

Depending on the desired result, we use `Math.floor`, `Math.ceil`, or `Math.round` -- it's important to pick the right one.

But yes, using one of those is (almost always) better than just casting to `(int)` if the value might be negative.

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

PR: https://git.openjdk.org/jfx/pull/924


More information about the openjfx-dev mailing list