Find out a monitor’s size / resolution in Eclipse SWT
For Single Monitor :
For Multi 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);
i really like this article please keep it up.best modem router combo
ReplyDelete