Search in sources :

Example 56 with Browser

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

Example 57 with Browser

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

the class FileUpload 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("File Upload");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.set(OpenFileCallback.class, (params, tell) -> tell.open(Paths.get("file.txt")));
    browser.mainFrame().ifPresent(mainFrame -> {
        mainFrame.loadHtml("Please specify a file, or a set of files:<br>\n" + "<input type='file' name='datafile' size='40'>");
    });
}
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 58 with Browser

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

the class FilterImages 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("Filter Images");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    engine.network().set(BeforeUrlRequestCallback.class, params -> {
        if (params.urlRequest().resourceType() == IMAGE) {
            return BeforeUrlRequestCallback.Response.cancel();
        }
        return BeforeUrlRequestCallback.Response.proceed();
    });
    browser.navigation().loadUrl("https://www.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 59 with Browser

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

the class FindText 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);
        JTextField searchField = new JTextField("Text to find");
        searchField.addActionListener(e -> browser.textFinder().find(searchField.getText(), findResult -> System.out.println("Matches found: " + findResult.numberOfMatches())));
        JFrame frame = new JFrame("Find Text");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(searchField, BorderLayout.NORTH);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().loadUrl("https://www.google.com");
}
Also used : SwingUtilities(javax.swing.SwingUtilities) JTextField(javax.swing.JTextField) Browser(com.teamdev.jxbrowser.browser.Browser) HARDWARE_ACCELERATED(com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) WindowConstants(javax.swing.WindowConstants) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) JTextField(javax.swing.JTextField) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 60 with Browser

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

the class GetHtml 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("Get HTML");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);
    });
    Navigation navigation = browser.navigation();
    // Add the callback for waiting till the page is loaded.
    navigation.on(FrameLoadFinished.class, event -> {
        if (event.frame().isMain()) {
            browser.mainFrame().ifPresent(frame -> System.out.println("HTML = " + frame.html()));
        }
    });
    navigation.loadUrl("https://www.teamdev.com/jxbrowser#features");
}
Also used : Navigation(com.teamdev.jxbrowser.navigation.Navigation) 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