屏幕显示尺寸

nit*_*ite 4 java

嗨我正在写一个图形程序,我一直在寻找一种方法来获得正在使用的屏幕的物理尺寸.我可以以像素为单位获得屏幕大小以及逻辑分辨率.我似乎无法找到的任何地方都可以获得任何显示器规格中的物理尺寸(例如19" - 376 x 301 mm).问题是,这些信息甚至存储在操作系统的任何位置,当它加载时正在使用的特定屏幕的驱动程序?我正在编写的程序需要在Mac和Windows上运行.

谢谢!

NT

k1r*_*1r0 5

在SWT中,您可以使用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));
Run Code Online (Sandbox Code Playgroud)