Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX WebView font issue on Mac

Tags:

java

macos

javafx

Some sites show gibberish characters instead of the correct text. It only happens on Macs.

For example with GMapsFX: enter image description here

Online site: enter image description here

Might be related to OS X 10.11 or 10.12. I tested it with Java 1.8.0_121.

Is there any fix or workaround for this issue?

like image 568
Erel Avatar asked Jan 31 '17 08:01

Erel


People also ask

What is WebView in JavaFX?

JavaFX WebView is used to show the web pages, that’s why the name webView here. It acts as a mini or a small browser that is able to represent the pages on the view.

How to display JavaScript and CSS code inside a JavaFX application?

It is capable of showing CSS, HTML, and JAVASCRIPT code on the webView, inside the JavaFX application. To use this we need to import the library from the JavaFX while programming.

Is there a bug in JavaFX when filesystem is null?

That is not a bug in JavaFX. We can make the error more elegant, by checking on the FileSystem class being null, and if so throwing a Java Exception (instead of a VM crash). But there are many places where this happens, and we should be careful not to decrease performance.


2 Answers

The error, in my case, was not related to system font. I solved the problem by setting the user agent for the web engine. Here is the string I used (Firefox on Windows x64):

Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0

like image 90
Dũng Trần Trung Avatar answered Oct 03 '22 10:10

Dũng Trần Trung


please load all font in system when java application launched. but is not best answer...sorry

List<String> fontFamilies = Font.getFamilies();
for (String fontFamily: fontFamilies) {
   Font.font(fontFamily);
}
like image 34
Tom Marvolo Riddle Avatar answered Oct 03 '22 11:10

Tom Marvolo Riddle