Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)


By default, zoom functionality is enabled in JxBrowser. You can zoom the web page using the Browser.zoomIn(), Browser.zoomOut(), Browser.zoomReset(), Browser.setZoomLevel() methods or using touch gestures in the environment with touch screen. If you would like to disable zoom for specific Browser instance and don't let the end user to zoom the web page loaded in this Browser instance, then you can use the Browser.setZoomEnabled() method.(默认情况下,JxBrowser中启用了缩放功能。您可以使用Browser.zoomIn(),Browser.zoomOut(),Browser.zoomReset(),Browser.setZoomLevel()方法或在带有触摸屏的环境中使用触摸手势来缩放网页。如果要禁用特定浏览器实例的缩放并且不让最终用户缩放此浏览器实例中加载的网页,则可以使用Browser.setZoomEnabled()方法。)


For example:(例如:)

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;

public class ZoomSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
        BrowserView view = new BrowserView(browser);

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        // Disabling zoom for the browser instance.
        browser.setZoomEnabled(false);

        browser.loadURL("https://google.com");
    }
}

Once you call the browser.setZoomEnabled(false) method in the example above, the Chromium engine will ignore all attempts to change zoom level programmatically via JxBrowser Zoom API and using touch gestures on a touch screen device. If zoom level of the loaded the web page has been already changed, the Browser.setZoomEnabled(false) function call will reset zoom to 100% and disable zoom functionality.(在上述示例中调用browser.setZoomEnabled(false)方法后,Chromium引擎将忽略所有通过JxBrowser Zoom API并以触摸屏设备上的触摸手势以编程方式更改缩放级别的尝试。如果已加载网页的缩放级别已更改,则Browser.setZoomEnabled(false)函数调用会将缩放重置为100%,并禁用缩放功能。)