Search in sources :

Example 16 with Engine

use of com.teamdev.jxbrowser.engine.Engine 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 17 with Engine

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

the class BitmapToSwingImage method main.

public static void main(String[] args) throws IOException {
    try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
        Browser browser = engine.newBrowser();
        // Resize browser to the required dimension
        browser.resize(1024, 768);
        // Load the required web page and wait until it is loaded completely
        browser.navigation().loadUrlAndWait("https://www.google.com");
        Bitmap bitmap = browser.bitmap();
        // Convert the bitmap to java.awt.image.BufferedImage
        BufferedImage bufferedImage = BitmapImage.toToolkit(bitmap);
        // Save the image to a PNG file
        ImageIO.write(bufferedImage, "PNG", new File("bitmap.png"));
    }
}
Also used : Bitmap(com.teamdev.jxbrowser.ui.Bitmap) File(java.io.File) Engine(com.teamdev.jxbrowser.engine.Engine) BufferedImage(java.awt.image.BufferedImage) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 18 with Engine

use of com.teamdev.jxbrowser.engine.Engine 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 19 with Engine

use of com.teamdev.jxbrowser.engine.Engine 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 20 with Engine

use of com.teamdev.jxbrowser.engine.Engine 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

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