I think I can now answer my own question. Officially there does not seem to be any way to find out what the physical DPIs of your screen are. The only way seems to be to use some private API like in the following example:
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Screen;
import javafx.stage.Stage;
public class PixelScaleTest extends Application {
public static double getPixelScale(Screen screen) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = Screen.class.getDeclaredMethod("getScale");
m.setAccessible(true);
return ((Float) m.invoke(screen)).doubleValue();
}
@Override
public void start(Stage primaryStage) throws Exception {
try {
System.out.println("PixelScale: " + getPixelScale(Screen.getPrimary()));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e) {
e.printStackTrace();
}
Platform.exit();
}
public static void main(String[] args) {
launch(args);
}
}
With the pixel scale factor you can compute your physical DPIs. On a standard Screen this factor should be 1.0 and on a Mac Retina it should be 2.0.