Search in sources :

Example 31 with BrowserView

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

the class SuppressKey method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    browser.set(PressKeyCallback.class, params -> {
        if (isDigit(params.event().keyChar())) {
            return PressKeyCallback.Response.suppress();
        }
        return PressKeyCallback.Response.proceed();
    });
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Suppress the Key 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("<textarea></textarea>");
    });
}
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 32 with BrowserView

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

the class UserAgent method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).userAgent("My User Agent String").build());
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("User Agent");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().loadUrl("http://whatsmyuseragent.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 33 with BrowserView

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

the class VoiceRecognition method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).googleApiKey("your_api_key").googleDefaultClientId("your_client_id").googleDefaultClientSecret("your_client_secret").build());
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Voice Recognition");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    // To test the voice recognition click the "Search by voice" icon in the search field.
    browser.navigation().loadUrl("https://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 34 with BrowserView

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

the class DemoApp method main.

public static void main(String[] args) {
    // Set your JxBrowser license key.
    System.setProperty("jxbrowser.license.key", "ENTER YOUR LICENSE KEY HERE");
    EngineOptions.Builder options = EngineOptions.newBuilder(HARDWARE_ACCELERATED);
    // #docfragment "enable-remote-debugging-port"
    // Enable the remote debugging port.
    options.remoteDebuggingPort(9222);
    // #enddocfragment "enable-remote-debugging-port"
    // Creating Chromium engine.
    Engine engine = Engine.newInstance(options.build());
    Browser browser = engine.newBrowser();
    // Print the web page's title once the page is loaded.
    browser.navigation().on(LoadFinished.class, event -> {
        System.out.println("Title: " + browser.title());
    });
    SwingUtilities.invokeLater(() -> {
        final BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Demo App");
        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, 500);
        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 BrowserView

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

the class DomKeyEvents method main.

public static void main(String[] args) {
    EngineOptions options = EngineOptions.newBuilder(HARDWARE_ACCELERATED).build();
    Engine engine = Engine.newInstance(options);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("DOM Keyboard Event Listener ");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    loadHtmlAndWait(browser);
    findInputField(browser).ifPresent(element -> {
        element.addEventListener(KEY_DOWN, DomKeyEvents::printEventDetails, false);
        element.addEventListener(KEY_PRESS, DomKeyEvents::printEventDetails, false);
        element.addEventListener(KEY_UP, DomKeyEvents::printEventDetails, false);
    });
}
Also used : JFrame(javax.swing.JFrame) 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)

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