JavaFX controls have large size on Raspberry Pi

David Grieve David.Grieve at
Mon Apr 20 20:25:17 UTC 2020

The sizes of controls are controlled by CSS styles. Things like borders, backgrounds, padding, insets, all of
that defaults to the styles in a stylesheet. Most sizes are 'em' units, meaning they are relative to the size 
of the font. JavaFX CSS will use the Font.getDefault() font size if there is no font explicitly set in either the 
styles or in the application code. 

I would start by looking at what Font.getDefault().getSize() returns since everything should be based off that. 
It could also be an issue with the default stylesheets themselves. 

-----Original Message-----
From: openjfx-dev <openjfx-dev-bounces at> On Behalf Of Alexander Scherbatiy
Sent: Monday, April 20, 2020 2:16 PM
To: openjfx-dev at
Subject: [EXTERNAL] JavaFX controls have large size on Raspberry Pi


I run a simple JavaFX application which shows a button with jdk 14.0.1 on Raspberry Pi and the drawn button has large size.

This is because of the algorithm which is used by
PrismFontFactory.getSystemFontSize() method [1] to select a system font size.
If a system is embedded then the font size is calculated as

     int screenDPI = Screen.getMainScreen().getResolutionY();
     systemFontSize = ((float) screenDPI) / 6f; // 12 points

and the system is detected as embedded because the armv6hf architecture is defined as embedded in the armv6hf.gradle file [2].

Raspberri Pi can work both with small touch displays and with big monitors. It looks like Raspberry Pi should support two modes for font size calculation: one for small screens and another for large.

I would like to contribute a fix for this but I do not know how the right fix could look like.
Should there be a special screen size so for smaller screens the font is is proportional to the screen size and for bigger screens the font size is fixed?
Is there a way to check that used screen is from embedded device?
May be it should be solved in different way?


JavaFX application:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class ButtonFX extends Application {
     public static void main(String[] args) {

     public void start(Stage primaryStage) {
         primaryStage.setTitle("Hello World!");
     Button button = new Button("Hello, World!");

         StackPane root = new StackPane();
         primaryStage.setScene(new Scene(root, 300, 250));;


More information about the openjfx-dev mailing list