Screen display size

2020-04-07 19:09发布

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

标签: java
7条回答
小情绪 Triste *
2楼-- · 2020-04-07 20:05

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));
查看更多
登录 后发表回答