[Snippet] Find out a monitor’s size / resolution in Eclipse SWT, on a multi-monitor setup

Recently I needed to find out the resolution of the monitor that is displaying my Eclipse RCP application, while I had two monitors in use.

In SWT, this can easily be done using org.eclipse.swt.widgets.Monitor.getBounds(), which canbe utilized in a multi-monitor setup as follows.

Monitor[] monitors = getShell().getDisplay().getMonitors();
Monitor activeMonitor = null;

Rectangle r = getShell().getBounds();
for (int i = 0; i < monitors.length; i++) {
    if (monitors[i].getBounds().intersects(r)) {
        activeMonitor = monitors[i];
System.out.println("The resolution of the active monitor is " + 
    activeMonitor.getBounds().width + " x " + 
If you found this post helpful, you may want to consider donating to help cover server costs.
Tagged with: , , , , , , , ,
Posted in Eclipse RCP, Snippet, SWT

Leave a Comment

%d bloggers like this: