What is the most straightforward way to apply a UI...
# tornadofx
n
What is the most straightforward way to apply a UI scale of 1.2 for the entire JavaFX application?
Want to do something like this: 1. Detect primary screen size, OS, and resolution 2. If screen size is 14", OS is Linux, and resolution is 1080p then go to step 3 3. Apply a UI scaling factor of 1.2 application wide
r
I believe DPI support was added in Java 9
n
Using Java 8 (via ZuluFX), which is missing the required UI scaling features since TornadoFX isn't compatible with Java 9 and above.
Is it possible to detect the physical display size?
Trying to get the scale via this method (uses reflection tricks) however it doesn't work (getScale method not found): https://stackoverflow.com/a/29048708
Seems as though detecting the physical display size (NOT the resolution) isn't possible 🙁 . Some GUI toolkits like GTK can provide the screen size although that is heavily dependent on the display providing the information (not all displays provide their screen size).
a
@Ruckus @napperley The hacky way would be to acquire resolution and then get screen DPI. DPI is the product of screen size and resolution, look into some formulas (how DPI is calculated), and I think you might be able to get the real screen size. something like this might work, I think:
Copy code
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
double h = size.getHeight() / dpi;
double w = size.getWidth() / dpi;
double diag = Math.hypot(h, w);
Be aware that it's AWT and it has some limitations, like multimonitor configuration. So you can replace Toolkit calls with
Screen#
methods (like
getDpi()
and
getPrimary().getVisualBounds()
).