This guide shows how to work with Zoom API.

JxBrowser allows to zoom content of a web page or of all web pages, get notifications when the zoom level of a web page has been changed, override the default zoom level, etc.

To work with the global zoom that will apply to all web pages please use the ZoomLevels class. An instance of this class you can obtain from Profile. For example:

ZoomLevels zoomLevels = profile.zoomLevels();
val zoomLevels = profile.zoomLevels()

If you use Engine.zoomLevels() then you get the ZoomLevels instance associated with the default profile.

To control zoom of a web page loaded in a Browser instance use the Zoom class.

Default Zoom Level

The default zoom level for all web pages is 100%. To change the default zoom level please use the ZoomLevels.defaultLevel(ZoomLevel) method.

The following code sets the default zoom level for all web pages to 150%:


Controlling Zoom

You can zoom content of a web page loaded in Browser programmatically using the Zoom class or using touch gestures in the environments with touch screen.

Zoom level is configured for each host separately. If you set a zoom level for the http://www.a.com web page, it will not be changed for the http://www.b.com web page.

To change the zoom level you need to wait until the web page is loaded completely.

Zoom In

To perform zoom in on a currently loaded web page use the following method:


Zoom Out

To perform zoom out on a currently loaded web page use the following method:


Setting Zoom Level

The following code sets zoom level of the loaded web page to 200%:


Resetting Zoom

To reset zoom level to the default value use the following code:


Disabling Zoom

You can disable zoom for all web pages loaded in a Browser using the Zoom.disable() method. This method disables the zoom functionality and resets the zoom level to the default value. After that all attempts to change the zoom level programmatically via JxBrowser Zoom API and using touch gestures on a touch screen device will be ignored.

For example:


Zoom Events

To get notifications when the zoom level for a particular web page has been changed use the ZoomLevelChanged event. For example:

zoomLevels.on(ZoomLevelChanged.class, event -> {
    Host host = event.host();
    ZoomLevel zoomLevel = event.level();
zoomLevels.on(ZoomLevelChanged::class.java) { event ->
    val host = event.host()
    val zoomLevel = event.level()

Pinch to Zoom

Currently, JxBrowser does not support zoom via a pinch-to-zoom trackpad gesture on macOS.

Go Top