Search in sources :

Example 1 with ZoomLevels

use of com.teamdev.jxbrowser.zoom.ZoomLevels in project JxBrowser-Examples by TeamDev-IP.

the class ZoomLevel method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Change Zoom Level");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    // Listen to the zoom changed events.
    ZoomLevels levels = engine.zoomLevels();
    levels.on(ZoomLevelChanged.class, event -> System.out.println("Url: " + event.host() + "\n" + "Zoom level: " + event.level()));
    Navigation navigation = browser.navigation();
    navigation.on(FrameLoadFinished.class, event -> {
        if (event.frame().isMain()) {
            browser.zoom().level(com.teamdev.jxbrowser.zoom.ZoomLevel.P_200);
        }
    });
    navigation.loadUrl("https://www.google.com");
}
Also used : Navigation(com.teamdev.jxbrowser.navigation.Navigation) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) ZoomLevels(com.teamdev.jxbrowser.zoom.ZoomLevels) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)1 Engine (com.teamdev.jxbrowser.engine.Engine)1 Navigation (com.teamdev.jxbrowser.navigation.Navigation)1 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)1 ZoomLevels (com.teamdev.jxbrowser.zoom.ZoomLevels)1 JFrame (javax.swing.JFrame)1