Search in sources :

Example 66 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class JsAccessibleMethod method main.

public static void main(String[] args) {
    try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
        Browser browser = engine.newBrowser();
        browser.mainFrame().ifPresent(frame -> {
            JsObject jsObject = frame.executeJavaScript("window");
            if (jsObject != null) {
                // Inject Java object into JavaScript and associate it
                // with the "window.java" JavaScript property.
                jsObject.putProperty("java", new JavaObject());
            }
            // Call the annotated public method of the injected Java object from JS.
            frame.executeJavaScript("window.java.sayHello()");
        });
    }
}
Also used : JsObject(com.teamdev.jxbrowser.js.JsObject) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 67 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class JsConsoleEvents 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("JS Console Listener");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.on(ConsoleMessageReceived.class, event -> {
        ConsoleMessage consoleMessage = event.consoleMessage();
        System.out.printf("Level: %s\nMessage: %s%n", consoleMessage.level().name(), consoleMessage.message());
    });
    browser.mainFrame().ifPresent(frame -> frame.executeJavaScript("console.error(\"Error message\");"));
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) ConsoleMessage(com.teamdev.jxbrowser.js.ConsoleMessage) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 68 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class LoadUrl 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("Load URL");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().loadUrl("https://www.google.com");
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 69 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class CustomCss 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("Custom CSS");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.set(InjectCssCallback.class, params -> InjectCssCallback.Response.inject("body { background-color: orange; }"));
    browser.navigation().loadUrl("about:blank");
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 70 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class DispatchKeyEvents 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("Dispatch key event");
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                engine.close();
            }
        });
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.add(view);
        frame.setSize(800, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    loadHtmlAndWait(browser, HTML);
    dispatchKey(browser, 'h');
    dispatchKey(browser, 'i');
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)70 Engine (com.teamdev.jxbrowser.engine.Engine)70 JFrame (javax.swing.JFrame)50 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)46 BorderLayout (java.awt.BorderLayout)8 HARDWARE_ACCELERATED (com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED)7 SwingUtilities (javax.swing.SwingUtilities)7 WindowConstants (javax.swing.WindowConstants)7 EngineOptions (com.teamdev.jxbrowser.engine.EngineOptions)6 Document (com.teamdev.jxbrowser.dom.Document)5 Frame (com.teamdev.jxbrowser.frame.Frame)5 JsObject (com.teamdev.jxbrowser.js.JsObject)5 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)5 WindowAdapter (java.awt.event.WindowAdapter)4 WindowEvent (java.awt.event.WindowEvent)4 OFF_SCREEN (com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN)3 Navigation (com.teamdev.jxbrowser.navigation.Navigation)3 Bitmap (com.teamdev.jxbrowser.ui.Bitmap)3 BrowserView (com.teamdev.jxbrowser.view.javafx.BrowserView)3 BrowserView (com.teamdev.jxbrowser.view.swt.BrowserView)3