Screen display size

前端 未结 7 1064
长情又很酷
长情又很酷 2021-01-19 03:50

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

7条回答
  •  甜味超标
    2021-01-19 04:19

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

提交回复
热议问题