How to get screen size in Java?
Not screen resolution, screen/monitor size in inch and aspect ratio. Application developed has to display some kind of test that has to be the same size regardless to screen size and aspect ratio. Lets say we want to display a rectangle that is 2 cm wide and 2 cm high and we want it to be the same size for every possible type of display adapter.
I think that the answer is that it is not achievable in pure Java, and possibly not at all.
You can get hold of the displayable screen size in pixels and the nominal scaling (dpi) in Java, via the default Toolkit
object. However, these are often inaccurate ... and that would lead to non-square squares.
You might be able to get more accurate values via native code, but this would definitely be non-portable. This Q/A says it is impossible - How to get screen's physical size (i.e. in inches)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With