Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get screen size in Java [duplicate]

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.

like image 816
Tomasz Kaszycki Avatar asked Mar 14 '13 11:03

Tomasz Kaszycki


1 Answers

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)?

like image 142
Stephen C Avatar answered Sep 23 '22 17:09

Stephen C