Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screen display size

Tags:

java

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

like image 835
nite Avatar asked Dec 17 '22 19:12

nite


2 Answers

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));
like image 119
k1r0 Avatar answered Dec 19 '22 08:12

k1r0


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.

like image 42
Denis Tulskiy Avatar answered Dec 19 '22 09:12

Denis Tulskiy