Search in sources :

Example 31 with Browser

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

the class DisablePdfViewer method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Plugins plugins = engine.plugins();
    // #docfragment "disabling-pdf-viewer"
    plugins.settings().disablePdfViewer();
    // #enddocfragment "disabling-pdf-viewer"
    Browser browser = engine.newBrowser();
    invokeLater(() -> {
        // Display a Swing frame with embedded BrowserView.
        showGui(browser);
        // Now, if you load a PDF document, it will not be displayed in the
        // PDF Viewer and will be downloaded instead.
        browser.navigation().loadUrl("http://www.orimi.com/pdf-test.pdf");
    });
}
Also used : Engine(com.teamdev.jxbrowser.engine.Engine) Plugins(com.teamdev.jxbrowser.plugin.Plugins) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 32 with Browser

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

the class DisableZoom 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("Disable Zoom");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().loadUrlAndWait("https://www.google.com");
    // Disabling zoom.
    browser.zoom().disable();
    // Setting zoom to 300% that will not be applied.
    browser.zoom().level(ZoomLevel.P_300);
}
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 33 with Browser

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

the class SamplePart method createComposite.

@PostConstruct
public void createComposite(Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    Engine engine = Engine.newInstance(EngineOptions.newBuilder(RenderingMode.HARDWARE_ACCELERATED).licenseKey("your_license_key").build());
    Browser browser = engine.newBrowser();
    Text addressBar = new Text(parent, SWT.SINGLE);
    addressBar.setText("https://google.com");
    addressBar.addListener(SWT.Traverse, event -> {
        if (event.detail == SWT.TRAVERSE_RETURN) {
            browser.navigation().loadUrl(addressBar.getText());
        }
    });
    browser.navigation().loadUrl(addressBar.getText());
    GridData textGrid = new GridData();
    textGrid.horizontalAlignment = GridData.FILL;
    addressBar.setLayoutData(textGrid);
    BrowserView view = BrowserView.newInstance(parent, browser);
    view.setLayoutData(new GridData(FILL, FILL, true, true));
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) BrowserView(com.teamdev.jxbrowser.view.swt.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser) PostConstruct(javax.annotation.PostConstruct)

Example 34 with Browser

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

the class TargetApp method main.

public static void main(String[] args) {
    // Set your JxBrowser license key.
    System.setProperty("jxbrowser.license.key", "your_license_key");
    // #docfragment "forward-remote-debugging-port"
    // Create a builder for EngineOptions.
    EngineOptions.Builder builder = EngineOptions.newBuilder(HARDWARE_ACCELERATED);
    // Configure Engine with the remote debugging port obtained from the command line args.
    remoteDebuggingPortFromCommandLine(args).ifPresent(builder::remoteDebuggingPort);
    // #enddocfragment "forward-remote-debugging-port"
    // Creating Chromium engine.
    Engine engine = Engine.newInstance(builder.build());
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        // Creating Swing component for rendering web content
        // loaded in the given Browser instance.
        BrowserView view = BrowserView.newInstance(browser);
        // Creating and displaying Swing app frame.
        JFrame frame = new JFrame();
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                engine.close();
            }
        });
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 700);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        browser.navigation().loadUrl("https://google.com");
    });
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) EngineOptions(com.teamdev.jxbrowser.engine.EngineOptions) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 35 with Browser

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

the class HelloWorld method main.

public static void main(String[] args) {
    // Initialize Chromium.
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    // Create a Browser instance.
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        JFrame frame = new JFrame("JxBrowser AWT/Swing");
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                // Shutdown Chromium and release allocated resources.
                engine.close();
            }
        });
        // Create and embed Swing BrowserView component to display web content.
        frame.add(BrowserView.newInstance(browser));
        frame.setSize(1280, 800);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        // Load the required web page.
        browser.navigation().loadUrl("https://html5test.com/");
    });
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) 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