Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force anti-aliasing in JavaFX fonts?

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] 
like image 782
Fappaz Avatar asked Jun 17 '14 00:06

Fappaz


People also ask

How do I make text bold in JavaFX?

Making Text Bold or Italic To make the text look bold, use the FontWeight constant of the font method as shown in Example 8. t. setFont(Font. font("Verdana", FontWeight.

What is the default Font for JavaFX?

There is a Segoe UI as default Font on your Windows 7 system, but the version is 5.01 per default.


2 Answers

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!

like image 106
Fappaz Avatar answered Sep 24 '22 00:09

Fappaz


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

Must be called before loading FXML template

like image 24
Adem Kouki Avatar answered Sep 24 '22 00:09

Adem Kouki