How to force anti-aliasing in JavaFX fonts?
Asked Answered
C

2

41

While testing the GUI of my JavaFX 8 application, I noticed that some labels are not displaying anti-aliased text. After some googling and struggling, I found out a very annoying thing that is happening. The anti-aliasing is being applied only on labels which font size is greater than 80px. Here is an example comparing JavaFX and Swing applications with AA applied:

enter image description here

Sample code: https://gist.github.com/anonymous/be60bb89181376ff12aa

Is there a way to force the AA in all font sizes? Does this happen to you too? I searched for a similar bug on JavaFX Jira, but nobody is complaining about that so far. Maybe I should open one for this?

Some info that may help:

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
Windows 8.1 64 bits [Version 6.3.9600]
Chive answered 17/6, 2014 at 0:14 Comment(1)
I have opened a bug on Jira for this.Chive
C
59

By default, JavaFX 8 uses modena.css to set the LCD anti aliasing, which doesn't seem to smooth out fonts in some cases. When the font size is larger than 80 px, the AA technique switches to grey scale AA (for performance reasons). So, to achieve smooth edges at any size, grey scale AA should be used instead.

This can be done either via JavaFX CSS:

.text{
    -fx-font-smoothing-type: gray;
}

Or system arguments:

-Dprism.lcdtext=false

Or setting system properties (before loading the FXML):

System.setProperty("prism.lcdtext", "false");

Thanks everyone who replied on Jira!

Chive answered 25/6, 2014 at 22:0 Comment(2)
I think that the default text smoothing type is "gray" (see docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html), but the Modena CSS set it to "lcd".Facies
Worth noting that if the UI is loaded from an FXML template, the System.setProperty("prism.lcdtext", "false"); should be called before loading it, otherwise it’ll make no effect.Clear
G
2

System.setProperty("prism.lcdtext", "false");

Must be called before loading FXML template

Goldagoldarina answered 21/5, 2020 at 5:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.