Search in sources :

Example 11 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class ContentListening method main.

public static void main(String[] args) {
    // #docfragment "engine-creation"
    Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).build());
    Browser browser = engine.newBrowser();
    // #enddocfragment "engine-creation"
    // #docfragment "embed-browser-view"
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Content Listening");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    // #enddocfragment "embed-browser-view"
    // #docfragment "inject-js"
    browser.set(InjectJsCallback.class, params -> {
        Frame frame = params.frame();
        String window = "window";
        JsObject jsObject = frame.executeJavaScript(window);
        if (jsObject == null) {
            throw new IllegalStateException(format("'%s' JS object not found", window));
        }
        jsObject.putProperty("java", new JavaObject());
        return Response.proceed();
    });
    // #enddocfragment "inject-js"
    // #docfragment "frame-load-finished"
    browser.navigation().on(FrameLoadFinished.class, event -> {
        String javaScript = load("observer.js");
        event.frame().executeJavaScript(javaScript);
    });
    // #enddocfragment "frame-load-finished"
    // #docfragment "load-page"
    String html = load("index.html");
    String base64Html = Base64.getEncoder().encodeToString(html.getBytes(UTF_8));
    String dataUrl = "data:text/html;base64," + base64Html;
    browser.navigation().loadUrl(dataUrl);
// #enddocfragment "load-page"
}
Also used : JsObject(com.teamdev.jxbrowser.js.JsObject) Frame(com.teamdev.jxbrowser.frame.Frame) JFrame(javax.swing.JFrame) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 12 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class AuthenticationDialog 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("Hello World");
        engine.network().set(AuthenticateCallback.class, createAuthenticationPopup(frame));
        frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 500);
        frame.setVisible(true);
        browser.navigation().loadUrl("http://httpbin.org/basic-auth/user/passwd");
    });
}
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 13 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class BrowserViewInJInternalFrame method createInternalFrame.

private static JInternalFrame createInternalFrame(String title, String url, int offset) {
    // To display BrowserView in Swing JInternalFrame, the engine must be configured
    // with the OFF_SCREEN rendering mode. In case of the HARDWARE_ACCELERATED rendering
    // mode we will get a well known issue with mixing heavyweight and lightweight
    // components. Read more about this limitation at
    // https://jxbrowser-support.teamdev.com/docs/guides/browser-view.html#mixing-heavyweight-and-lightweight
    Engine engine = Engine.newInstance(OFF_SCREEN);
    Browser browser = engine.newBrowser();
    browser.navigation().loadUrl(url);
    BrowserView view = BrowserView.newInstance(browser);
    JInternalFrame frame = new JInternalFrame(title, true);
    frame.setContentPane(view);
    frame.setLocation(100 + offset, 100 + offset);
    frame.setSize(400, 400);
    frame.setVisible(true);
    return frame;
}
Also used : BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) JInternalFrame(javax.swing.JInternalFrame) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 14 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class SuppressMouse method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    browser.set(PressMouseCallback.class, params -> {
        if (params.event().keyModifiers().isShiftDown()) {
            return PressMouseCallback.Response.proceed();
        }
        return PressMouseCallback.Response.suppress();
    });
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Suppress the Mouse Pressed event");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(500, 400);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.mainFrame().ifPresent(mainFrame -> {
        mainFrame.loadHtml("<button onclick=\"clicked()\">click holding shift</button>" + "<script>function clicked() {alert('clicked');}</script>");
    });
}
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 15 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class WebSocket 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("Web Socket");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().loadUrl("https://www.websocket.org/echo.html");
}
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)

Aggregations

BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)49 Browser (com.teamdev.jxbrowser.browser.Browser)47 JFrame (javax.swing.JFrame)47 Engine (com.teamdev.jxbrowser.engine.Engine)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)5 Document (com.teamdev.jxbrowser.dom.Document)4 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)4 WindowAdapter (java.awt.event.WindowAdapter)4 WindowEvent (java.awt.event.WindowEvent)4 Navigation (com.teamdev.jxbrowser.navigation.Navigation)3 JButton (javax.swing.JButton)3 Frame (com.teamdev.jxbrowser.frame.Frame)2 Path (java.nio.file.Path)2 Content (com.intellij.ui.content.Content)1 UnsupportedRenderingModeException (com.teamdev.jxbrowser.browser.UnsupportedRenderingModeException)1 SpellCheckCompleted (com.teamdev.jxbrowser.browser.event.SpellCheckCompleted)1