Hi I'm writing a graphics program and I've been searching for a way to get the physical size of the screen being used. I can get the size of the screen in pixels and also the logical resolution. What I can't seem to find is anywhere to get the physical dimensions that are always in the specs for any monitor (eg 19"- 376 x 301 mm). Question, is this information even stored anywhere in the OS when it loads the driver for the particular screen being used? The program I'm writing needs to work on Mac and Windows.
Thanks!
nt
In SWT you can use getShell().getDisplay().getPrimaryMonitor().getClientArea();
final Display display = getShell().getDisplay();
final Monitor monitor = display.getPrimaryMonitor();
final Rectangle rect;
if (monitor != null) {
rect = monitor.getClientArea();
} else {
// In case we cannot find the primary monitor get the entire display rectangle
// Note that it may include the dimensions of multiple monitors.
rect = display.getBounds();
}
System.out.println("Monitor width=" + String.valueOf(rect.width));
System.out.println("Monitor height=" + String.valueOf(rect.height));
I don't think it's possible with java. You can try to write some jni code if this feature is absolutely essential in your program. Otherwise, just ask the user for their monitor size.
EDIT Looks like SWT can give you DPI, and you can calculate the monitor size with it: http://www.java2s.com/Code/JavaAPI/org.eclipse.swt.graphics/DevicegetDPI.htm
But, you'd have to use SWT :) Which is actually not that bad choice if you want to develop good-looking programs for Mac.
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