Search in sources :

Example 16 with Browser

use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.

the class DefaultOpenPopupCallback method on.

@Override
public Response on(Params params) {
    Browser browser = params.popupBrowser();
    Platform.runLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        Stage stage = new Stage();
        StackPane root = new StackPane();
        Scene scene = new Scene(root);
        root.getChildren().add(view);
        stage.setScene(scene);
        updateBounds(stage, params.initialBounds());
        stage.setOnCloseRequest(event -> browser.close());
        browser.on(TitleChanged.class, event -> Platform.runLater(() -> stage.setTitle(event.title())));
        browser.on(BrowserClosed.class, event -> Platform.runLater(stage::close));
        browser.on(UpdateBoundsRequested.class, event -> Platform.runLater(() -> updateBounds(stage, event.bounds())));
        stage.show();
    });
    return Response.proceed();
}
Also used : Stage(javafx.stage.Stage) BrowserView(com.teamdev.jxbrowser.view.javafx.BrowserView) Scene(javafx.scene.Scene) StackPane(javafx.scene.layout.StackPane) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 17 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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 18 with Browser

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

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

use of com.teamdev.jxbrowser.browser.Browser 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)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)73 Engine (com.teamdev.jxbrowser.engine.Engine)70 JFrame (javax.swing.JFrame)51 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)47 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 BrowserView (com.teamdev.jxbrowser.view.javafx.BrowserView)5 WindowAdapter (java.awt.event.WindowAdapter)5 WindowEvent (java.awt.event.WindowEvent)5 Scene (javafx.scene.Scene)5 BrowserView (com.teamdev.jxbrowser.view.swt.BrowserView)4 OFF_SCREEN (com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN)3 Navigation (com.teamdev.jxbrowser.navigation.Navigation)3