Search code examples
javaswtmultiple-monitors

SWT: Method Monitor#getZoom() cannot be found


The org.eclipse.swt.widgets.Monitor class is supposed to have an instance method called getZoom, which should return the zoom factor set on the particular monitor. It is documented here (after clicking on "Monitor"): https://help.eclipse.org/2021-03/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/package-summary.html

However, when trying to compile the following code...

Monitor monitor = Display.getDefault().getPrimaryMonitor();
int zoom = monitor.getZoom();

..., I get an error saying:

java: cannot find symbol
  symbol:   method getZoom()
  location: variable monitor of type org.eclipse.swt.widgets.Monitor

The method is documented to exist since SWT version 3.107, and I'm using version 4.6.1. All other methods of the Monitor class work as expected.

What am I missing here?

(If there is further information needed to answer this question, please feel free to ask.)


Solution

  • SWT versions do not match Eclipse versions. 4.6.1 is your Eclipse version (Eclipse Neon), this contains SWT version 3.105.1 which is too old.

    SWT 3.107 was first included in Eclipse 4.8 (Eclipse Photon). I think later versions extend the platforms on which zoom is supported so you should try to move to the current Eclipse 2021-03 (2021-06 shortly)