There seems to be an issue with the JWebBrowser when using Windows' high DPI scaling options.
Easily reproducible - in Windows 10, set UI scaling on one (of two monitors) to 125%
JWebBrowser does appear to be drawing at 125% scale, but it does so on both monitors, even the one with no scaling. It also doesn't seem to be updating its bounds to match that 125% - when on the scaled monitor, it does not render in the upscaled space, even though the content is clearly upscaled within the space it is rendering (Image 1)
One artifact of this is that, if you retrieve the mouse position in the JWebBrowser on the un-scaled monitor, the values are incorrect and do not match the values that should be showing (because the content is scaled 125% when it should not be). Image ex2 shows this.
And mouse behavior on the scaled monitor is also strange - within the rendered area, mouse values are incorrect, the same way they are on the unscaled monitor. Within the area that is not rendering, mouse values are still being returned from the browser, and they are the correct value for what it should be due to scaling. Here is a GIF showing how the values change across that border https://gyazo.com/634bfe83d3f41cc32e7621fab43c26e4
Lastly, unlike the rest of the swing UI, the browser does not update to the scale in realtime; the browser must be reinitialized to recognize that the scale has changed. But this is less of an issue
(Image 3 just to show what the content looks like when I set UI scaling to 100%)
Hi,
Are you using a recent version of the SWT library? I think the old version that I ship had many problems with High DPI... Could you try and let me know if some bugs are still present?
I think the latest for your platform is "swt-4.19-win32-win32-x86_64.zip" which can be found here:
https://download.eclipse.org/eclipse/downloads/drops4/R-4.19-202103031800/
Cheers,
-Christopher
Just to confirm I downloaded and imported the swt that you linked, but am still having the same problems. The DJProject installs have also been refreshed, but no change
Hi,
The bounds occupied by the web browser should be fixed in version: 1.0.3-20220131
Please try with "DJNativeSwing-SWT-1-0-3-20220131.zip".
I haven't done any conversion of the mouse coordinates for mouse events. I suppose that I would have to convert the physical pixels into conceptual pixels so that if there are physically 500 pixels Swing should receive an event for 400 pixels if the scaling factor is 125%. I am not sure yet if this could cause other problems... Any opinion?
Cheers,
-Christopher
Mouse coordinates should probably be okay once it's scaled; coordinates should still be based on the unscaled resolution, which judging by what it was giving previously, is probably what it outputs now
Won't have a chance to try it for a little while, though, so I'm just guessing at what it's doing right now
If that's not what it's doing, then yeah, your method sounds fine. The events should never give values outside of the bounds the user defined for the window (unscaled); but of course, the window should be displayed larger than what they defined, if it's scaled - so scaling the detected mouse position back down should do fine
I added the version "DJNativeSwing-SWT-1-0-3-20220201.zip" that applies the scaling factor to the mouse coordinates.
There are other parts of the API that might not respect scaling, but which are probably not used anymore, such as printing a native component to an image. Unless someone actually needs that, I don't intend to fix scaling there. In the case of printing to an image, it is unclear how to solve it: should we assume that the passed in image on which to print has the unscaled bounds? Etc.
If you get to test it, please let me know the outcome!
Cheers,
-Christopher