Posts

Showing posts from January, 2017

Find out a monitor’s size / resolution in Eclipse SWT

For Single Monitor : @Inject @Optional public void receiveActiveShell(@Named(IServiceConstants.ACTIVE_SHELL) final Shell shell) { if (shell != null) { final Display display = shell.getDisplay(); final Rectangle screenSize = display.getBounds(); final Point size = shell.getSize(); shell.setLocation((int) (screenSize.width - size.x) / 2, (int) (screenSize.height - size.y) / 2); } } For Multi Monitor : Monitor[] monitors = getShell().getDisplay().getMonitors(); Monitor activeMonitor = null; Rectangle rect = shell.getBounds(); for (int i = 0; i < monitors.length; i++) { if (monitors[i].getBounds().intersects(rect)) { activeMonitor = monitors[i]; } } System.out.println("The resolution of the active monitor is " + activeMonitor.getBounds().width + " x " + activeMonitor.getBounds().height);