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

Kevin Rushforth kcr at openjdk.org
Fri Oct 28 23:46:31 UTC 2022


On Fri, 28 Oct 2022 16:23:10 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:

>> 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.

I think in this case, `Math.floor()` is what you want. I wonder, though, whether it needs to be converted to an `int` at all? It looks like everywhere it is used, it can be kept as a double.

Btw, I almost wrote a comment asking a question as to whether you were using the values of x, y, width, and height correctly, because I got confused that you were using a Dimension to hold an x,y point. If you decide to keep it as a Dimension, I might suggest adding a clarifying comment.

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

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


More information about the openjfx-dev mailing list