JavaFX controls have large size on Raspberry Pi

Alexander Scherbatiy alexander.scherbatiy at bell-sw.com
Mon Apr 20 18:15:48 UTC 2020


Hello,

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?

[1] 
https://github.com/openjdk/jfx/blob/ec8608f39576035d41e8e532e9334b979b859543/modules/javafx.graphics/src/main/java/com/sun/javafx/font/PrismFontFactory.java#L1944
[2] 
https://github.com/openjdk/jfx/blob/ec8608f39576035d41e8e532e9334b979b859543/buildSrc/armv6hf.gradle#L182

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) {
         launch(args);
     }

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

         StackPane root = new StackPane();
         root.getChildren().add(button);
         primaryStage.setScene(new Scene(root, 300, 250));
         primaryStage.show();
     }
}
----------------------------

Thanks,
Alexander.




More information about the openjfx-dev mailing list