FlatLaf icon indicating copy to clipboard operation
FlatLaf copied to clipboard

Possible inconsistencies on large monitor with scaling

Open ijabz opened this issue 2 years ago • 7 comments

I have recently moved to Flatlaf, I also moved from Java 11 to Java 17. A couple of user who use scaling on their large monitors have complained the text in my application is now too large compared to other applications. Even without scaling the text seems to be larger than other apps, however in my test on normal size monitor it looks fine and is actually smaller then other apps.

I'm really not clear if there is a Flatlaf issue, Java 17 issue, coding error in my app or user error, but if you could offer any assistance would be appreciated.

Rather than repeat everything here the thread with screenshots can be seen at

https://community.jthink.net/t/blur-update-annoying-enlarged-view/10735/18

ijabz avatar Apr 28 '22 09:04 ijabz

That's strange 😕

Are you modifying the default font in some way in your app. E.g. UIManager.put( "defaultFont", myFont );

Or do you set system properties flatlaf.uiScale or sun.java2d.uiScale?

GTinOZ's problem: Font size is correct at startup, but changes after a few seconds to double size (from 17px to 34px). Icons and gaps are unchanged.

I've no idea why this happens. FlatLaf gets the font from desktop property win.messagebox.font and also updates the font if that changes. E.g. user changes text size in Windows settings (Accessibility > Text size). Changing display scaling does not change font size.

To find out whether this is the case, you could add some logging to your app. E.g.:

// setup FlatLaf
FlatLightLaf.setup();

Toolkit toolkit = Toolkit.getDefaultToolkit();

// log initial font
log( toolkit.getDesktopProperty( "win.messagebox.font" ) );

// listen to system font changes
toolkit.addPropertyChangeListener( "win.messagebox.font", e -> {
    log( toolkit.getDesktopProperty( "win.messagebox.font" ) );
} );

BTW the default font on Windows is:

java.awt.Font[family=Segoe UI,name=Segoe UI,style=plain,size=12]

GTinOZ: Interestingly, if I change the scale in this setting to (say) 150%, all my other apps shrink, but the Jaikoz app doesn’t.

That's strange because Java 17 apps automatically change scaling when Windows display scaling is changed. Are you sure that GTinOZ is using Java 17? Do you bundle Java 17 with our app?

Another (probably unrelated) thing I noticed on the screenshots from GTinOZ and Dani82 is that both are not getting FlatLaf's window decorations (dark title bar and menubar embedded into window title bar), but paultaylor's screenshot show them.

So either both use Windows on ARM processors (which FlatLaf does not yet support), or access to temporary directory is denied (which is necessary to extract FlatLaf DLL from Jar).

To fix this, you could extract the DLLs from flatlaf.jar, distribute them with your app, and set system property flatlaf.nativeLibraryPath (see https://www.formdev.com/flatlaf/system-properties/) so that FlatLaf can find them. See also PR #453

DevCharly avatar Apr 28 '22 11:04 DevCharly

thankyou for looking at this, I think the dll extraction thing is likely the problem. On my devlopment machine where i am adminstrator it is all fine, but I just downloaded my application and tried it another PC, and it also incorrectly continued to show lighttitle bars when in dark mode.

I'm using the standard jpackage tool for Windows, so for the existing installed version of Jaikoz on my dev machine I have removed the dlls from flatlaf.jar to sucessfully replicate the the titlebar issue, and then I tried to fix it by putting the dlls into C:/Program Files/Jthink/Jaikoz/app

and adding a line to Jaikoz.cfg

[JavaOptions]
java-options=-Djpackage.app-version=11.4
java-options=-Dhttps.protocols=TLSv1.1,TLSv1.2
java-options=-Dflatlaf.nativeLibraryPath="C:\Program Files\Jthink\Jaikoz\app"

but it has no effect, the title bar remains light

So I seem to be doing something wrong but cant see what ?

ijabz avatar Apr 29 '22 09:04 ijabz

To answer some of your other questions They are on Intel not arm, Im not modifying fonts or using any flatlaf scaling

ijabz avatar Apr 29 '22 10:04 ijabz

Okay fixed the dll issue, didnt realize have to store in folder structure that matches the jar, i.e C:\Program Files\Jthink\Jaikoz\app\com\formdev\flatlaf\natives, if I put in app it actually works without using Dflatlaf.nativeLibraryPath guess must look there by default. I will get users to try and see if helps with font problem

ijabz avatar Apr 29 '22 11:04 ijabz

didnt realize have to store in folder structure that matches the jar, i.e C:\Program Files\Jthink\Jaikoz\app\com\formdev\flatlaf\natives

Hmm, that's not true. If system property flatlaf.nativeLibraryPath is set to a directory, then the DLL is loaded from that directory:

https://github.com/JFormDesigner/FlatLaf/blob/37c375e2fa20697379fd7859c4a5315643f5efc6/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowsNativeWindowBorder.java#L133-L141

DevCharly avatar May 12 '22 12:05 DevCharly

OK, sorry must just be me getting confused have that bit working now. One customer got round issue by using -Dflatlaf.uiScale to shrink size, but don't know the underlying cause.

ijabz avatar May 12 '22 15:05 ijabz

Please see issue #580, I think you are also encountering the problem where JPackage creates a windows executable without a manifest, this causes problems with dpi-awareness which can result in large fonts. I was able to solve this by using OpenJDK 19 for creating a JPackage'd app.

remcopoelstra avatar Sep 04 '22 13:09 remcopoelstra